From f40323c7c56f29ed40fe236328a0c7ff8af7ce5d Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <31414959+0xSysR3ll@users.noreply.github.com> Date: Thu, 12 Mar 2026 17:58:11 +0100 Subject: [PATCH] fix(migration): repair postgres blocklist id sequence (#2686) --- .../1772000000000-FixBlocklistIdDefault.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 server/migration/postgres/1772000000000-FixBlocklistIdDefault.ts diff --git a/server/migration/postgres/1772000000000-FixBlocklistIdDefault.ts b/server/migration/postgres/1772000000000-FixBlocklistIdDefault.ts new file mode 100644 index 00000000..fbf07048 --- /dev/null +++ b/server/migration/postgres/1772000000000-FixBlocklistIdDefault.ts @@ -0,0 +1,20 @@ +import type { MigrationInterface, QueryRunner } from 'typeorm'; + +export class FixBlocklistIdDefault1772000000000 implements MigrationInterface { + name = 'FixBlocklistIdDefault1772000000000'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "blocklist" ALTER COLUMN "id" SET DEFAULT nextval('public."blocklist_id_seq"'::regclass)` + ); + + await queryRunner.query( + `SELECT setval('public."blocklist_id_seq"', COALESCE((SELECT MAX("id") FROM "blocklist"), 0) + 1, false)` + ); + } + + public async down(): Promise { + // Intentionally left empty: dropping the DEFAULT on blocklist.id would + // reintroduce the original bug and break blocklist inserts. + } +}