TypeORM migration file for @Tree('closure-table') entity

338 Views Asked by At
@Entity()
@Tree('closure-table')
class Comment {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @TreeParent()
    parent: Comment;

    @TreeChildren({ cascade: true })
    children: Comment[];
}

Is there any way to generate a TypeORM migration file for the above entity? I couldnt find it in the documentation.

1

There are 1 best solutions below

0
Artur On
 CREATE TABLE comment (
    id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
    parent_id uuid REFERENCES comment (id),
    name VARCHAR(128) NOT NULL,
    created_at timestamp NOT NULL DEFAULT now(),
    updated_at timestamp NOT NULL DEFAULT now()
  );
  
  CREATE TABLE comment_closure (
    id_ancestor uuid REFERENCES comment (id) NOT NULL,
    id_descendant uuid REFERENCES comment (id) NOT NULL,
    PRIMARY KEY (id_ancestor, id_descendant)
  );

  CREATE INDEX comment_closure_id_ancestor_index ON comment_closure (id_ancestor);
  CREATE INDEX comment_closure_id_descendant_index ON comment_closure (id_descendant);