From a4bd40c2b0189740f687acb1cf9c5bf2e04ba1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Wed, 25 Mar 2026 23:33:59 -0400 Subject: [PATCH] feat(01-01): set busy_timeout and extend migration runner type - Set 5000ms busy_timeout via DatabaseSync constructor option in openConnection() - Extend migration runner type to support both sql string and fn callback migrations - fn-based migrations execute inside existing transaction for atomicity --- src/main/database.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/database.ts b/src/main/database.ts index 7dc9f034..21bd3a9a 100644 --- a/src/main/database.ts +++ b/src/main/database.ts @@ -2979,7 +2979,7 @@ export class AppDatabase { .map((row) => row.version), ); - const migrations: Array<{ version: number; name: string; sql: string }> = [ + const migrations: Array<{ version: number; name: string; sql?: string; fn?: () => void }> = [ { version: 1, name: "add_workspace_lock_lease", @@ -3203,8 +3203,12 @@ export class AppDatabase { if (applied.has(migration.version)) continue; try { this.transaction(() => { - for (const stmt of migration.sql.split(";").map((s) => s.trim()).filter(Boolean)) { - this.db.prepare(stmt).run(); + if (migration.fn) { + migration.fn(); + } else if (migration.sql) { + for (const stmt of migration.sql.split(";").map((s) => s.trim()).filter(Boolean)) { + this.db.prepare(stmt).run(); + } } this.db .prepare("insert into schema_migrations (version, name, applied_at) values (?, ?, ?)") @@ -3709,7 +3713,7 @@ export class AppDatabase { } private openConnection(): SqliteDatabase { - return new DatabaseSync(this.dbPath); + return new DatabaseSync(this.dbPath, { timeout: 5000 }); } }