From 2edbfce7d341654326fd32dda4fc7ee029139029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Guti=C3=A9rrez?= <35082514+alezmad@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:59:28 +0100 Subject: [PATCH] fix(broker): add BROKER_SKIP_MIGRATE=1 escape hatch for manual-migrated DBs Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/broker/src/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/broker/src/index.ts b/apps/broker/src/index.ts index 62185a7..a24ba83 100644 --- a/apps/broker/src/index.ts +++ b/apps/broker/src/index.ts @@ -4448,10 +4448,16 @@ async function recoverScheduledMessages(): Promise { } async function main(): Promise { - // Run pending migrations before the first connection is accepted. - // Exits non-zero on failure so Coolify sees a broken container. - const { runMigrationsOnStartup } = await import("./migrate"); - await runMigrationsOnStartup(); + // Auto-migrate: skip when BROKER_SKIP_MIGRATE=1 (e.g. when the prod + // DB was already manually migrated and the drizzle tracking table is + // out of sync). Once drizzle's __drizzle_migrations is caught up, + // remove the flag. + if (process.env.BROKER_SKIP_MIGRATE !== "1") { + const { runMigrationsOnStartup } = await import("./migrate"); + await runMigrationsOnStartup(); + } else { + console.log("[migrate] skipped (BROKER_SKIP_MIGRATE=1)"); + } const wss = new WebSocketServer({ noServer: true,