fix(broker): use sql.unsafe for SET lock_timeout in migrate
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-16 12:55:04 +01:00
parent 05729ad8a4
commit 9f3a82dd63

View File

@@ -49,15 +49,12 @@ export async function runMigrationsOnStartup(): Promise<void> {
const sql = postgres(url, { const sql = postgres(url, {
max: 1, max: 1,
onnotice: () => { /* quiet */ }, onnotice: () => { /* quiet */ },
// Statement-level safety net in case a long ALTER holds row locks.
// 5 min per statement is plenty for schema DDL.
statement_timeout: 5 * 60 * 1000,
}); });
try { try {
// Set a lock_timeout for this session — PG will refuse to block more // SET doesn't accept parameterized values ($1) — use unsafe() for
// than N ms on any lock acquisition (we only hold one at a time). // the literal. The value is a hardcoded constant, not user input.
await sql`SET lock_timeout = ${LOCK_ACQUIRE_TIMEOUT_MS}`; await sql.unsafe(`SET lock_timeout = '${LOCK_ACQUIRE_TIMEOUT_MS}ms'`);
// Try to grab the advisory lock; poll if someone else holds it. // Try to grab the advisory lock; poll if someone else holds it.
const deadline = Date.now() + LOCK_ACQUIRE_TIMEOUT_MS; const deadline = Date.now() + LOCK_ACQUIRE_TIMEOUT_MS;