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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user