export class MemorietTextLayersAndViews1783801000000 {
    name = "MemorietTextLayersAndViews1783801000000";
    async up(queryRunner) {
        await queryRunner.query(`ALTER TABLE "memoriet" ADD COLUMN IF NOT EXISTS "textLayers" jsonb NOT NULL DEFAULT '[]'::jsonb`);
        await queryRunner.query(`CREATE TABLE IF NOT EXISTS "memoriet_view" ("id" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "viewedAt" TIMESTAMP WITH TIME ZONE NOT NULL, "memorietId" character varying(32) NOT NULL, "viewerId" character varying(32) NOT NULL, CONSTRAINT "PK_memoriet_view" PRIMARY KEY ("id"))`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_memoriet_view_createdAt" ON "memoriet_view" ("createdAt")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_memoriet_view_viewedAt" ON "memoriet_view" ("viewedAt")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_memoriet_view_memorietId" ON "memoriet_view" ("memorietId")`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_memoriet_view_viewerId" ON "memoriet_view" ("viewerId")`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_memoriet_view_memorietId_viewerId" ON "memoriet_view" ("memorietId", "viewerId")`);
        await queryRunner.query(`DO $$ BEGIN ALTER TABLE "memoriet_view" ADD CONSTRAINT "FK_memoriet_view_memoriet" FOREIGN KEY ("memorietId") REFERENCES "memoriet"("id") ON DELETE CASCADE ON UPDATE NO ACTION; EXCEPTION WHEN duplicate_object THEN NULL; END $$`);
        await queryRunner.query(`DO $$ BEGIN ALTER TABLE "memoriet_view" ADD CONSTRAINT "FK_memoriet_view_viewer" FOREIGN KEY ("viewerId") REFERENCES "user"("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 "memoriet_view"`);
        await queryRunner.query(`ALTER TABLE "memoriet" DROP COLUMN IF EXISTS "textLayers"`);
    }
}
