fix: prevent database is locked on concurrent startup

Set busy_timeout before journal_mode=WAL in db.ts so SQLite retries
for 10s instead of failing immediately with the default 0ms timeout.

Extract migration into a dedicated Docker Compose service so both
jetstream and api wait for it to complete before opening the database.
This commit is contained in:
Julien Calixte
2026-03-21 12:30:17 +01:00
parent 92e0dbe0d4
commit ac2b70a260
2 changed files with 15 additions and 3 deletions

View File

@@ -3,10 +3,10 @@ import type { Note } from "./note.ts";
export const db = new Database(Deno.env.get("SQLITE_PATH") ?? "notes.db");
try {
db.exec("PRAGMA busy_timeout=10000");
db.exec("PRAGMA journal_mode=WAL");
db.exec("PRAGMA busy_timeout=5000");
const [row] = db.prepare("PRAGMA journal_mode").all<{ journal_mode: string }>();
console.log(`[db] journal_mode=${row.journal_mode}, busy_timeout=5000`);
console.log(`[db] journal_mode=${row.journal_mode}, busy_timeout=10000`);
} catch (e) {
console.error("[db] failed to set PRAGMAs:", e);
}