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) <noreply@anthropic.com>
This commit is contained in:
Mitchell R 2026-05-24 05:05:31 +02:00
parent 664e6e1548
commit 5c367203c6
No known key found for this signature in database

View file

@ -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],