From c52b48b0f5105c6036480248e9e833b37f17fa87 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 17 Apr 2022 22:14:32 +0000 Subject: [PATCH] sql: update version first in migration transactions In execute_migration transaction first update the version, and only then execute the rest of the migration. This ensures that transaction is immediately recognized as write transaction and there is no need to promote it from read transaction to write transaction later, e.g. in the case of "DROP TABLE IF EXISTS" that is a read only operation if the table does not exist. Promoting a read transaction to write transaction may result in an error if database is locked. --- src/sql/migrations.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 92f1c9551..02f13ecf3 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -723,14 +723,14 @@ impl Sql { async fn execute_migration(&self, query: &'static str, version: i32) -> Result<()> { self.transaction(move |transaction| { - transaction.execute_batch(query)?; - // set raw config inside the transaction transaction.execute( "UPDATE config SET value=? WHERE keyname=?;", paramsv![format!("{version}"), VERSION_CFG], )?; + transaction.execute_batch(query)?; + Ok(()) }) .await