From c6120b7cc0a213ae5b401fa004ba8cb14ad30935 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 21:47:48 +0800 Subject: [PATCH] fix: make sqlite migrations atomic --- crates/xmedia-bot/src/db.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/xmedia-bot/src/db.rs b/crates/xmedia-bot/src/db.rs index 1a515d5..11d8f40 100644 --- a/crates/xmedia-bot/src/db.rs +++ b/crates/xmedia-bot/src/db.rs @@ -174,9 +174,10 @@ fn migrate(conn: &Connection) -> rusqlite::Result<()> { if version >= target { continue; } - conn.execute_batch(statement)?; - // `PRAGMA` does not take bind parameters; the value is our own index. - conn.execute_batch(&format!("PRAGMA user_version = {target}"))?; + let tx = conn.unchecked_transaction()?; + tx.execute_batch(statement)?; + tx.execute_batch(&format!("PRAGMA user_version = {target}"))?; + tx.commit()?; } Ok(()) }