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.
This commit is contained in:
link2xt
2022-04-17 22:14:32 +00:00
parent 893794f4e7
commit c52b48b0f5

View File

@@ -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