Compare commits

...

2 Commits

Author SHA1 Message Date
dignifiedquire
03ebe86297 fix: try executing migration stepwise 2023-03-17 13:49:54 +01:00
dignifiedquire
f8d3baa2ee fix: do not delete columns
This requires currently too much memory, crashing on larger instances
2023-03-17 13:05:59 +01:00

View File

@@ -691,15 +691,20 @@ CREATE INDEX smtp_messageid ON imap(rfc724_mid);
sql.set_db_version(98).await?;
}
if dbversion < 99 {
sql.execute_migration(
"ALTER TABLE msgs DROP COLUMN server_folder;
ALTER TABLE msgs DROP COLUMN server_uid;
ALTER TABLE msgs DROP COLUMN move_state;
ALTER TABLE chats DROP COLUMN draft_timestamp;
ALTER TABLE chats DROP COLUMN draft_txt",
sql.execute_migration_parts(
[
"ALTER TABLE msgs DROP COLUMN server_folder;",
"ALTER TABLE msgs DROP COLUMN server_uid;",
"ALTER TABLE msgs DROP COLUMN move_state;",
"ALTER TABLE chats DROP COLUMN draft_timestamp;",
"ALTER TABLE chats DROP COLUMN draft_txt",
],
99,
)
.await?;
// Reverted above, as it requires to load the whole DB in memory.
// sql.set_db_version(99).await?;
}
let new_version = sql
@@ -753,4 +758,37 @@ impl Sql {
Ok(())
}
async fn execute_migration_parts(
&self,
queries: impl IntoIterator<Item = &'static str>,
version: i32,
) -> Result<()> {
for query in queries {
self.transaction(move |transaction| {
transaction.execute_batch(query)?;
Ok(())
})
.await
.with_context(|| format!("execute_migration failed for version {version}"))?;
}
self.transaction(move |transaction| {
// set raw config inside the transaction
transaction.execute(
"UPDATE config SET value=? WHERE keyname=?;",
paramsv![format!("{version}"), VERSION_CFG],
)?;
Ok(())
})
.await
.context("failed to set version")?;
let mut lock = self.config_cache.write().await;
lock.insert(VERSION_CFG.to_string(), Some(format!("{version}")));
drop(lock);
Ok(())
}
}