mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user