import { MigrationInterface, QueryRunner } from 'typeorm'; export class AddProductEntities1660058692487 implements MigrationInterface { name = 'AddProductEntities1660058692487'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` CREATE TABLE "aggregate_products" ( "id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "identifiers" text array NOT NULL DEFAULT '{}', "discoverable" boolean, "asin" text, "dimensions" text, "colorCode" text, "annotations" text, "description" text, "name" text, "price" double precision NOT NULL, "isAvailable" boolean, "distributor" text, "distributorSKU" text, "imageUrls" text array NOT NULL DEFAULT '{}', CONSTRAINT "PK_dcd132aa42050029d059410bcf0" PRIMARY KEY ("id") ) `); await queryRunner.query(` CREATE INDEX "IDX_cdb6b8133e9f28de0b17bc110a" ON "aggregate_products" ("identifiers") `); await queryRunner.query(` CREATE TABLE "product_variants" ( "id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "identifiers" text array NOT NULL DEFAULT '{}', "discoverable" boolean, "asin" text, "dimensions" text, "colorCode" text, "annotations" text, "description" text, "name" text, "price" double precision NOT NULL, "isAvailable" boolean, "distributor" text, "distributorSKU" text, "imageUrls" text array NOT NULL DEFAULT '{}', "productId" uuid, CONSTRAINT "PK_281e3f2c55652d6a22c0aa59fd7" PRIMARY KEY ("id") ) `); await queryRunner.query(` CREATE INDEX "IDX_1ceb1230ecc0b95faf406e1fa2" ON "product_variants" ("identifiers") `); await queryRunner.query(` ALTER TABLE "retailer_products" ADD "aggregateProductId" uuid NOT NULL `); await queryRunner.query(` ALTER TABLE "retailer_product_variants" ADD "retailer" text NOT NULL `); await queryRunner.query(` ALTER TABLE "retailer_products" ADD CONSTRAINT "FK_87839253e3642f882e0f2225f7a" FOREIGN KEY ("aggregateProductId") REFERENCES "aggregate_products"("id") ON DELETE NO ACTION ON UPDATE NO ACTION `); await queryRunner.query(` ALTER TABLE "product_variants" ADD CONSTRAINT "FK_f515690c571a03400a9876600b5" FOREIGN KEY ("productId") REFERENCES "aggregate_products"("id") ON DELETE NO ACTION ON UPDATE NO ACTION `); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(` ALTER TABLE "product_variants" DROP CONSTRAINT "FK_f515690c571a03400a9876600b5" `); await queryRunner.query(` ALTER TABLE "retailer_products" DROP CONSTRAINT "FK_87839253e3642f882e0f2225f7a" `); await queryRunner.query(` ALTER TABLE "retailer_product_variants" DROP COLUMN "retailer" `); await queryRunner.query(` ALTER TABLE "retailer_products" DROP COLUMN "aggregateProductId" `); await queryRunner.query(` DROP INDEX "public"."IDX_1ceb1230ecc0b95faf406e1fa2" `); await queryRunner.query(` DROP TABLE "product_variants" `); await queryRunner.query(` DROP INDEX "public"."IDX_cdb6b8133e9f28de0b17bc110a" `); await queryRunner.query(` DROP TABLE "aggregate_products" `); } }