From 5c367203c665aa81223f9ef92b958128dcbb31e0 Mon Sep 17 00:00:00 2001 From: Mitchell R Date: Sun, 24 May 2026 05:05:31 +0200 Subject: [PATCH] fix(db): log failing PG migration index + SQL on error Was crashing silently during migration. Now logs which migration index failed and the first 200 chars of the SQL before rethrowing. Co-Authored-By: Claude Opus 4.6 (1M context) --- server/src/shared/db/init.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/shared/db/init.ts b/server/src/shared/db/init.ts index ec4fa10..7a2a079 100644 --- a/server/src/shared/db/init.ts +++ b/server/src/shared/db/init.ts @@ -52,7 +52,13 @@ export async function initDb( PRIMARY KEY (schema_name, version) )`); for (let i = currentVersion; i < TENANT_MIGRATIONS.length; i++) { - await adapter.exec(TENANT_MIGRATIONS[i]!); + try { + await adapter.exec(TENANT_MIGRATIONS[i]!); + } catch (err) { + log.warn(`PG migration ${i} failed: ${(err as Error).message}`); + log.warn(`SQL: ${TENANT_MIGRATIONS[i]!.slice(0, 200)}`); + throw err; + } await adapter.run( `INSERT INTO schema_migrations (schema_name, version) VALUES ('public', ?)`, [i + 1],