export class GroupActorActions1783701000000 {
    name = "GroupActorActions1783701000000";
    async up(queryRunner) {
        await queryRunner.query(`ALTER TABLE "note" ADD COLUMN IF NOT EXISTS "groupId" character varying(32)`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_note_groupId" ON "note" ("groupId")`);
        await queryRunner.query(`DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_note_groupId') THEN ALTER TABLE "note" ADD CONSTRAINT "FK_note_groupId" FOREIGN KEY ("groupId") REFERENCES "user_group"("id") ON DELETE SET NULL ON UPDATE NO ACTION; END IF; END $$`);
        await queryRunner.query(`ALTER TABLE "note_reaction" ADD COLUMN IF NOT EXISTS "groupId" character varying(32)`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_note_reaction_groupId" ON "note_reaction" ("groupId")`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_note_reaction_userId_noteId"`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_2ad0dfa7c5f662a9568d503f6c"`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_ad0c221b25672daf2df320a817"`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_note_reaction_user_note_personal" ON "note_reaction" ("userId", "noteId") WHERE "groupId" IS NULL`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_note_reaction_group_note" ON "note_reaction" ("groupId", "noteId") WHERE "groupId" IS NOT NULL`);
        await queryRunner.query(`DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_note_reaction_groupId') THEN ALTER TABLE "note_reaction" ADD CONSTRAINT "FK_note_reaction_groupId" FOREIGN KEY ("groupId") REFERENCES "user_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION; END IF; END $$`);
        await queryRunner.query(`ALTER TABLE "note_favorite" ADD COLUMN IF NOT EXISTS "groupId" character varying(32)`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_note_favorite_groupId" ON "note_favorite" ("groupId")`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_note_favorite_userId_noteId"`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_2f9b01a470a2b5d20a87f7520e"`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_0f4fb9ad355f3effff221ef245"`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_note_favorite_user_note_personal" ON "note_favorite" ("userId", "noteId") WHERE "groupId" IS NULL`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_note_favorite_group_note" ON "note_favorite" ("groupId", "noteId") WHERE "groupId" IS NOT NULL`);
        await queryRunner.query(`DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_note_favorite_groupId') THEN ALTER TABLE "note_favorite" ADD CONSTRAINT "FK_note_favorite_groupId" FOREIGN KEY ("groupId") REFERENCES "user_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION; END IF; END $$`);
        await queryRunner.query(`ALTER TABLE "muting" ADD COLUMN IF NOT EXISTS "groupId" character varying(32)`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_muting_groupId" ON "muting" ("groupId")`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_1eb9d9824a630321a29fd3b290"`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_muting_muterId_muteeId"`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_muting_user_mutee_personal" ON "muting" ("muterId", "muteeId") WHERE "groupId" IS NULL`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_muting_group_mutee" ON "muting" ("groupId", "muteeId") WHERE "groupId" IS NOT NULL`);
        await queryRunner.query(`DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_muting_groupId') THEN ALTER TABLE "muting" ADD CONSTRAINT "FK_muting_groupId" FOREIGN KEY ("groupId") REFERENCES "user_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION; END IF; END $$`);
        await queryRunner.query(`ALTER TABLE "blocking" ADD COLUMN IF NOT EXISTS "groupId" character varying(32)`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_blocking_groupId" ON "blocking" ("groupId")`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_98a1bc5cb30dfd159de056549f"`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_blocking_blockerId_blockeeId"`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_blocking_user_blockee_personal" ON "blocking" ("blockerId", "blockeeId") WHERE "groupId" IS NULL`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_blocking_group_blockee" ON "blocking" ("groupId", "blockeeId") WHERE "groupId" IS NOT NULL`);
        await queryRunner.query(`DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_blocking_groupId') THEN ALTER TABLE "blocking" ADD CONSTRAINT "FK_blocking_groupId" FOREIGN KEY ("groupId") REFERENCES "user_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION; END IF; END $$`);
        await queryRunner.query(`ALTER TABLE "call_blocking" ADD COLUMN IF NOT EXISTS "groupId" character varying(32)`);
        await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_call_blocking_groupId" ON "call_blocking" ("groupId")`);
        await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_call_blocking_blocker_blockee"`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_call_blocking_user_blockee_personal" ON "call_blocking" ("blockerId", "blockeeId") WHERE "groupId" IS NULL`);
        await queryRunner.query(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_call_blocking_group_blockee" ON "call_blocking" ("groupId", "blockeeId") WHERE "groupId" IS NOT NULL`);
        await queryRunner.query(`DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'FK_call_blocking_groupId') THEN ALTER TABLE "call_blocking" ADD CONSTRAINT "FK_call_blocking_groupId" FOREIGN KEY ("groupId") REFERENCES "user_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION; END IF; END $$`);
    }
    async down(queryRunner) {
        await queryRunner.query(`ALTER TABLE "call_blocking" DROP CONSTRAINT "FK_call_blocking_groupId"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_call_blocking_group_blockee"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_call_blocking_user_blockee_personal"`);
        await queryRunner.query(`CREATE UNIQUE INDEX "IDX_call_blocking_blocker_blockee" ON "call_blocking" ("blockerId", "blockeeId")`);
        await queryRunner.query(`DROP INDEX "public"."IDX_call_blocking_groupId"`);
        await queryRunner.query(`ALTER TABLE "call_blocking" DROP COLUMN "groupId"`);
        await queryRunner.query(`ALTER TABLE "blocking" DROP CONSTRAINT "FK_blocking_groupId"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_blocking_group_blockee"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_blocking_user_blockee_personal"`);
        await queryRunner.query(`CREATE UNIQUE INDEX "IDX_98a1bc5cb30dfd159de056549f" ON "blocking" ("blockerId", "blockeeId")`);
        await queryRunner.query(`DROP INDEX "public"."IDX_blocking_groupId"`);
        await queryRunner.query(`ALTER TABLE "blocking" DROP COLUMN "groupId"`);
        await queryRunner.query(`ALTER TABLE "muting" DROP CONSTRAINT "FK_muting_groupId"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_muting_group_mutee"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_muting_user_mutee_personal"`);
        await queryRunner.query(`CREATE UNIQUE INDEX "IDX_1eb9d9824a630321a29fd3b290" ON "muting" ("muterId", "muteeId")`);
        await queryRunner.query(`DROP INDEX "public"."IDX_muting_groupId"`);
        await queryRunner.query(`ALTER TABLE "muting" DROP COLUMN "groupId"`);
        await queryRunner.query(`ALTER TABLE "note_favorite" DROP CONSTRAINT "FK_note_favorite_groupId"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_favorite_group_note"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_favorite_user_note_personal"`);
        await queryRunner.query(`CREATE UNIQUE INDEX "IDX_note_favorite_userId_noteId" ON "note_favorite" ("userId", "noteId")`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_favorite_groupId"`);
        await queryRunner.query(`ALTER TABLE "note_favorite" DROP COLUMN "groupId"`);
        await queryRunner.query(`ALTER TABLE "note_reaction" DROP CONSTRAINT "FK_note_reaction_groupId"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_reaction_group_note"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_reaction_user_note_personal"`);
        await queryRunner.query(`CREATE UNIQUE INDEX "IDX_note_reaction_userId_noteId" ON "note_reaction" ("userId", "noteId")`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_reaction_groupId"`);
        await queryRunner.query(`ALTER TABLE "note_reaction" DROP COLUMN "groupId"`);
        await queryRunner.query(`ALTER TABLE "note" DROP CONSTRAINT "FK_note_groupId"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_note_groupId"`);
        await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "groupId"`);
    }
}
