brand new migrations that should work well
parent
c40d132584
commit
e092a862b2
|
@ -1,42 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableColumn } from 'typeorm';
|
||||
|
||||
export class initialize1625694002469 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE SEQUENCE items_serial
|
||||
AS bigint
|
||||
MINVALUE 140000000000
|
||||
START WITH 140000000000;
|
||||
`);
|
||||
|
||||
const items = new Table();
|
||||
items.name = 'item';
|
||||
const iid = new TableColumn();
|
||||
iid.name = 'id';
|
||||
iid.type = 'bigint';
|
||||
iid.default = "nextval('items_serial')";
|
||||
iid.isPrimary = true;
|
||||
iid.isUnique = true;
|
||||
iid.isNullable = false;
|
||||
items.addColumn(iid);
|
||||
const iname = new TableColumn();
|
||||
iname.name = 'name';
|
||||
iname.type = 'varchar(40)';
|
||||
iname.isNullable = false;
|
||||
items.addColumn(iname);
|
||||
const inotes = new TableColumn();
|
||||
inotes.name = 'notes';
|
||||
inotes.type = 'varchar(255)';
|
||||
inotes.isNullable = true;
|
||||
items.addColumn(inotes);
|
||||
|
||||
await queryRunner.createTable(items);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('items');
|
||||
await queryRunner.query(`
|
||||
DROP SEQUENCE items_serial;
|
||||
`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class initialize1625776986297 implements MigrationInterface {
|
||||
name = 'initialize1625776986297';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE SEQUENCE "items_serial" AS bigint MINVALUE 140000000000 START WITH 140000000000;`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "item" ("id" bigint NOT NULL DEFAULT nextval('items_serial'), "name" character varying NOT NULL, "notes" character varying, "parentId" bigint, CONSTRAINT "PK_d3c0c71f23e7adcf952a1d13423" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "item_closure_closure" ("id_ancestor" bigint NOT NULL, "id_descendant" bigint NOT NULL, CONSTRAINT "PK_251adfef42a155516a515eaf7d5" PRIMARY KEY ("id_ancestor", "id_descendant"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_854ec7dacad2df840aa8d4ee0a" ON "item_closure_closure" ("id_ancestor") `,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX "IDX_58bff82facc806857035e516c9" ON "item_closure_closure" ("id_descendant") `,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item" ADD CONSTRAINT "FK_2e3b654a1f669d356e259e7ca3c" FOREIGN KEY ("parentId") REFERENCES "item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_closure_closure" ADD CONSTRAINT "FK_854ec7dacad2df840aa8d4ee0a9" FOREIGN KEY ("id_ancestor") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_closure_closure" ADD CONSTRAINT "FK_58bff82facc806857035e516c9e" FOREIGN KEY ("id_descendant") REFERENCES "item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP SEQUENCE items_serial;`);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_closure_closure" DROP CONSTRAINT "FK_58bff82facc806857035e516c9e"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_closure_closure" DROP CONSTRAINT "FK_854ec7dacad2df840aa8d4ee0a9"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item" DROP CONSTRAINT "FK_2e3b654a1f669d356e259e7ca3c"`,
|
||||
);
|
||||
await queryRunner.query(`DROP INDEX "IDX_58bff82facc806857035e516c9"`);
|
||||
await queryRunner.query(`DROP INDEX "IDX_854ec7dacad2df840aa8d4ee0a"`);
|
||||
await queryRunner.query(`DROP TABLE "item_closure_closure"`);
|
||||
await queryRunner.query(`DROP TABLE "item"`);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue