import { MigrationInterface, QueryRunner } from 'typeorm'; export class InitProductsCrud1777811112018 implements MigrationInterface { name = 'InitProductsCrud1777811112018'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( `CREATE TABLE "digital_stock_items" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "content" text NOT NULL, "isSold" boolean NOT NULL DEFAULT false, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "productId" uuid, CONSTRAINT "PK_bfffac39999d57b14d445abeb2f" PRIMARY KEY ("id"))` ); await queryRunner.query(`CREATE TYPE "public"."products_priceunit_enum" AS ENUM('USD')`); await queryRunner.query(`CREATE TYPE "public"."products_type_enum" AS ENUM('digital')`); await queryRunner.query( `CREATE TABLE "products" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying NOT NULL, "price" numeric(12,2) NOT NULL, "priceUnit" "public"."products_priceunit_enum" NOT NULL DEFAULT 'USD', "type" "public"."products_type_enum" NOT NULL DEFAULT 'digital', "thumbnailUrl" character varying NOT NULL, "descriptionHtml" text NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, CONSTRAINT "PK_0806c755e0aca124e67c0cf6d7d" PRIMARY KEY ("id"))` ); await queryRunner.query( `ALTER TABLE "digital_stock_items" ADD CONSTRAINT "FK_f3ee7be0d350b6954b5d3c8bf32" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` ); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(`ALTER TABLE "digital_stock_items" DROP CONSTRAINT "FK_f3ee7be0d350b6954b5d3c8bf32"`); await queryRunner.query(`DROP TABLE "products"`); await queryRunner.query(`DROP TYPE "public"."products_type_enum"`); await queryRunner.query(`DROP TYPE "public"."products_priceunit_enum"`); await queryRunner.query(`DROP TABLE "digital_stock_items"`); } }