From 0f97ab258ff4870eccad84575bbcae3e6c5e8d75 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 6 Apr 2026 04:20:25 +0000 Subject: [PATCH] Fix migrate.mjs exiting with code 1 after successful migration client.end() in the finally block was throwing (postgres driver already cleaned up connections internally during migrate()), causing an unhandled rejection and exit code 1 despite the migration succeeding. - Use explicit process.exit(0)/exit(1) instead of relying on implicit exit - Wrap both client.end() calls with .catch(() => {}) to tolerate cleanup errors - Add onnotice: () => {} to suppress noisy NOTICE messages (schema/table already exists) that are normal on every idempotent re-run https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ --- scripts/migrate.mjs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/migrate.mjs b/scripts/migrate.mjs index 89cd316..09e89e6 100644 --- a/scripts/migrate.mjs +++ b/scripts/migrate.mjs @@ -13,14 +13,20 @@ if (!process.env.DATABASE_URL) { } console.log("Running database migrations..."); -const client = postgres(process.env.DATABASE_URL, { max: 1 }); +const client = postgres(process.env.DATABASE_URL, { + max: 1, + onnotice: () => {}, // suppress NOTICE messages (schema/table already exists, etc.) +}); + try { const db = drizzle(client); await migrate(db, { migrationsFolder: path.resolve(__dirname, "../drizzle") }); console.log("Migrations completed successfully"); } catch (err) { console.error("Migration failed:", err); + await client.end().catch(() => {}); process.exit(1); -} finally { - await client.end(); } + +await client.end().catch(() => {}); +process.exit(0);