fix: make sqlite migrations atomic

This commit is contained in:
2026-09-24 21:47:48 +08:00
parent 7b4e273533
commit c6120b7cc0
+4 -3
View File
@@ -174,9 +174,10 @@ fn migrate(conn: &Connection) -> rusqlite::Result<()> {
if version >= target { if version >= target {
continue; continue;
} }
conn.execute_batch(statement)?; let tx = conn.unchecked_transaction()?;
// `PRAGMA` does not take bind parameters; the value is our own index. tx.execute_batch(statement)?;
conn.execute_batch(&format!("PRAGMA user_version = {target}"))?; tx.execute_batch(&format!("PRAGMA user_version = {target}"))?;
tx.commit()?;
} }
Ok(()) Ok(())
} }