import { MigrationInterface, QueryRunner } from 'typeorm'; export class AddRetailerProductEntities1659402614873 implements MigrationInterface { name = 'AddRetailerProductEntities1659402614873'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( `CREATE TABLE "retailer_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, "source" text, "name" text, "price" double precision NOT NULL, "isAvailable" boolean, "distributor" text, "distributorSKU" text, "imageUrls" text array NOT NULL DEFAULT '{}', "retailer" text NOT NULL, CONSTRAINT "PK_a5a8ec42a7aa064d73b7fd67fc1" PRIMARY KEY ("id"))` ); await queryRunner.query( `CREATE INDEX "IDX_2e53e8bd55081d564659993264" ON "retailer_products" ("identifiers") ` ); await queryRunner.query( `CREATE TABLE "retailer_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, "source" text, "name" text, "price" double precision NOT NULL, "isAvailable" boolean, "distributor" text, "distributorSKU" text, "imageUrls" text array NOT NULL DEFAULT '{}', "productId" uuid, CONSTRAINT "PK_f55db92e2724ad6f621c9bad2c1" PRIMARY KEY ("id"))` ); await queryRunner.query( `CREATE INDEX "IDX_efc19e6f75f2950015e27d9a30" ON "retailer_product_variants" ("identifiers") ` ); await queryRunner.query( `ALTER TABLE "pages" ALTER COLUMN "lastScrapedAt" SET DEFAULT 'NOW()'` ); await queryRunner.query( `ALTER TABLE "products" ALTER COLUMN "lastScrapedAt" SET DEFAULT 'NOW()'` ); await queryRunner.query( `ALTER TABLE "retailer_product_variants" ADD CONSTRAINT "FK_e8ca3231fdafa4fc0c662d5b14a" FOREIGN KEY ("productId") REFERENCES "retailer_products"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` ); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query( `ALTER TABLE "retailer_product_variants" DROP CONSTRAINT "FK_e8ca3231fdafa4fc0c662d5b14a"` ); await queryRunner.query( `ALTER TABLE "products" ALTER COLUMN "lastScrapedAt" SET DEFAULT '2022-08-02 01:07:47.82147+00'` ); await queryRunner.query( `ALTER TABLE "pages" ALTER COLUMN "lastScrapedAt" SET DEFAULT '2022-08-02 01:07:47.82147+00'` ); await queryRunner.query( `DROP INDEX "public"."IDX_efc19e6f75f2950015e27d9a30"` ); await queryRunner.query(`DROP TABLE "retailer_product_variants"`); await queryRunner.query( `DROP INDEX "public"."IDX_2e53e8bd55081d564659993264"` ); await queryRunner.query(`DROP TABLE "retailer_products"`); } }