export class Plans1784200000000 {
    name = "Plans1784200000000";
    async up(queryRunner) {
        await queryRunner.query(`CREATE TABLE IF NOT EXISTS "plan" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE, "name" character varying(128) NOT NULL, "icon" character varying(64) NOT NULL, "description" character varying(512) NOT NULL DEFAULT '', CONSTRAINT "PK_plan" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_plan_name" ON "plan" ("name")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_plan_createdAt" ON "plan" ("createdAt")`);
        await queryRunner.query(`CREATE TABLE IF NOT EXISTS "user_plan" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "userId" character varying(32) NOT NULL, "planId" character varying(32) NOT NULL, CONSTRAINT "PK_user_plan" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_user_plan_user_plan" ON "user_plan" ("userId", "planId")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_user_plan_createdAt" ON "user_plan" ("createdAt")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_user_plan_userId" ON "user_plan" ("userId")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_user_plan_planId" ON "user_plan" ("planId")`);
        await queryRunner.query(`DO $$ BEGIN ALTER TABLE "user_plan" ADD CONSTRAINT "FK_user_plan_user" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION; EXCEPTION WHEN duplicate_object THEN NULL; END $$`);
        await queryRunner.query(`DO $$ BEGIN ALTER TABLE "user_plan" ADD CONSTRAINT "FK_user_plan_plan" FOREIGN KEY ("planId") REFERENCES "plan"("id") ON DELETE CASCADE ON UPDATE NO ACTION; EXCEPTION WHEN duplicate_object THEN NULL; END $$`);
    }
    async down(queryRunner) {
        await queryRunner.query(`DROP TABLE IF EXISTS "user_plan"`);
        await queryRunner.query(`DROP TABLE IF EXISTS "plan"`);
    }
}
