Fix DB init crash: wrap bulk migration in explicit transaction

The COMMIT without BEGIN failed in autocommit mode, crashing ProjectDB
init and leaving _shared_db as None ("Database not initialized").

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 00:03:13 +01:00
parent 0f134a1a20
commit 45ce264675
+6 -1
View File
@@ -74,6 +74,8 @@ class ProjectDB:
"""One-time bulk migration: merge separate lora strength keys in all stored sequences.""" """One-time bulk migration: merge separate lora strength keys in all stored sequences."""
rows = self.conn.execute("SELECT id, data FROM sequences").fetchall() rows = self.conn.execute("SELECT id, data FROM sequences").fetchall()
updated = 0 updated = 0
self.conn.execute("BEGIN")
try:
for row in rows: for row in rows:
data = json.loads(row["data"]) data = json.loads(row["data"])
original = row["data"] original = row["data"]
@@ -85,8 +87,11 @@ class ProjectDB:
(new_json, row["id"]), (new_json, row["id"]),
) )
updated += 1 updated += 1
if updated:
self.conn.execute("COMMIT") self.conn.execute("COMMIT")
except Exception:
self.conn.execute("ROLLBACK")
raise
if updated:
logger.info("Migrated lora keys in %d/%d sequences", updated, len(rows)) logger.info("Migrated lora keys in %d/%d sequences", updated, len(rows))
def close(self): def close(self):