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:
@@ -74,19 +74,24 @@ 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
|
||||||
for row in rows:
|
self.conn.execute("BEGIN")
|
||||||
data = json.loads(row["data"])
|
try:
|
||||||
original = row["data"]
|
for row in rows:
|
||||||
migrated = self._migrate_lora_keys(data)
|
data = json.loads(row["data"])
|
||||||
new_json = json.dumps(migrated)
|
original = row["data"]
|
||||||
if new_json != original:
|
migrated = self._migrate_lora_keys(data)
|
||||||
self.conn.execute(
|
new_json = json.dumps(migrated)
|
||||||
"UPDATE sequences SET data = ? WHERE id = ?",
|
if new_json != original:
|
||||||
(new_json, row["id"]),
|
self.conn.execute(
|
||||||
)
|
"UPDATE sequences SET data = ? WHERE id = ?",
|
||||||
updated += 1
|
(new_json, row["id"]),
|
||||||
if updated:
|
)
|
||||||
|
updated += 1
|
||||||
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):
|
||||||
|
|||||||
Reference in New Issue
Block a user