36 lines
1.9 KiB
TypeScript
36 lines
1.9 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
export class AddDiscountToCategory1781849627565 implements MigrationInterface {
|
|
name = 'AddDiscountToCategory1781849627565';
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.query(
|
|
`CREATE TABLE "discount_codes_categories" ("discountCodeId" uuid NOT NULL, "categoryId" uuid NOT NULL, CONSTRAINT "PK_a1d001587e1735737d233e956a5" PRIMARY KEY ("discountCodeId", "categoryId"))`
|
|
);
|
|
await queryRunner.query(
|
|
`CREATE INDEX "IDX_3126372e862e29a5374a8594b0" ON "discount_codes_categories" ("discountCodeId") `
|
|
);
|
|
await queryRunner.query(
|
|
`CREATE INDEX "IDX_1bcf070115fa8dc5ebb57d0fee" ON "discount_codes_categories" ("categoryId") `
|
|
);
|
|
await queryRunner.query(
|
|
`ALTER TABLE "discount_codes_categories" ADD CONSTRAINT "FK_3126372e862e29a5374a8594b0c" FOREIGN KEY ("discountCodeId") REFERENCES "discount_codes"("id") ON DELETE CASCADE ON UPDATE CASCADE`
|
|
);
|
|
await queryRunner.query(
|
|
`ALTER TABLE "discount_codes_categories" ADD CONSTRAINT "FK_1bcf070115fa8dc5ebb57d0fee8" FOREIGN KEY ("categoryId") REFERENCES "categories"("id") ON DELETE CASCADE ON UPDATE CASCADE`
|
|
);
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.query(
|
|
`ALTER TABLE "discount_codes_categories" DROP CONSTRAINT "FK_1bcf070115fa8dc5ebb57d0fee8"`
|
|
);
|
|
await queryRunner.query(
|
|
`ALTER TABLE "discount_codes_categories" DROP CONSTRAINT "FK_3126372e862e29a5374a8594b0c"`
|
|
);
|
|
await queryRunner.query(`DROP INDEX "public"."IDX_1bcf070115fa8dc5ebb57d0fee"`);
|
|
await queryRunner.query(`DROP INDEX "public"."IDX_3126372e862e29a5374a8594b0"`);
|
|
await queryRunner.query(`DROP TABLE "discount_codes_categories"`);
|
|
}
|
|
}
|