mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 14:56:33 +03:00
12
src/imex.rs
12
src/imex.rs
@@ -1137,4 +1137,16 @@ mod tests {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tests importing a backup from Delta Chat 1.30.3 for Android (core v1.86.0).
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_import_ancient_backup() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let context = &tcm.unconfigured().await;
|
||||||
|
|
||||||
|
let backup_path = Path::new("test-data/core-1.86.0-backup.tar");
|
||||||
|
imex(context, ImexMode::ImportBackup, backup_path, None).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use crate::constants::ShowEmails;
|
|||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::key::DcKey;
|
use crate::key::DcKey;
|
||||||
use crate::log::warn;
|
use crate::log::warn;
|
||||||
use crate::message::MsgId;
|
|
||||||
use crate::provider::get_provider_info;
|
use crate::provider::get_provider_info;
|
||||||
use crate::sql::Sql;
|
use crate::sql::Sql;
|
||||||
use crate::tools::{Time, inc_and_check, time_elapsed};
|
use crate::tools::{Time, inc_and_check, time_elapsed};
|
||||||
@@ -734,12 +733,6 @@ impl Sql {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_db_version_in_cache(&self, version: i32) -> Result<()> {
|
|
||||||
let mut lock = self.config_cache.write().await;
|
|
||||||
lock.insert(VERSION_CFG.to_string(), Some(format!("{version}")));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_migration(&self, query: &str, version: i32) -> Result<()> {
|
async fn execute_migration(&self, query: &str, version: i32) -> Result<()> {
|
||||||
self.execute_migration_transaction(
|
self.execute_migration_transaction(
|
||||||
|transaction| {
|
|transaction| {
|
||||||
@@ -1612,51 +1605,11 @@ CREATE INDEX msgs_status_updates_index2 ON msgs_status_updates (uid);
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if dbversion < 108 {
|
// Migration 108 is removed, it was using high level code
|
||||||
let version = 108;
|
// to split SMTP queue messages into chunks with smaller number of recipients
|
||||||
let chunk_size = context.get_max_smtp_rcpt_to().await?;
|
// and started to fail later as high level code started
|
||||||
sql.transaction(move |trans| {
|
// expecting `transports` table that is only added in future migrations.
|
||||||
Sql::set_db_version_trans(trans, version)?;
|
// Migration 108 was not changing the database schema.
|
||||||
let id_max =
|
|
||||||
trans.query_row("SELECT IFNULL((SELECT MAX(id) FROM smtp), 0)", (), |row| {
|
|
||||||
let id_max: i64 = row.get(0)?;
|
|
||||||
Ok(id_max)
|
|
||||||
})?;
|
|
||||||
while let Some((id, rfc724_mid, mime, msg_id, recipients, retries)) = trans
|
|
||||||
.query_row(
|
|
||||||
"SELECT id, rfc724_mid, mime, msg_id, recipients, retries FROM smtp \
|
|
||||||
WHERE id<=? LIMIT 1",
|
|
||||||
(id_max,),
|
|
||||||
|row| {
|
|
||||||
let id: i64 = row.get(0)?;
|
|
||||||
let rfc724_mid: String = row.get(1)?;
|
|
||||||
let mime: String = row.get(2)?;
|
|
||||||
let msg_id: MsgId = row.get(3)?;
|
|
||||||
let recipients: String = row.get(4)?;
|
|
||||||
let retries: i64 = row.get(5)?;
|
|
||||||
Ok((id, rfc724_mid, mime, msg_id, recipients, retries))
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.optional()?
|
|
||||||
{
|
|
||||||
trans.execute("DELETE FROM smtp WHERE id=?", (id,))?;
|
|
||||||
let recipients = recipients.split(' ').collect::<Vec<_>>();
|
|
||||||
for recipients in recipients.chunks(chunk_size) {
|
|
||||||
let recipients = recipients.join(" ");
|
|
||||||
trans.execute(
|
|
||||||
"INSERT INTO smtp (rfc724_mid, mime, msg_id, recipients, retries) \
|
|
||||||
VALUES (?, ?, ?, ?, ?)",
|
|
||||||
(&rfc724_mid, &mime, msg_id, recipients, retries),
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("migration failed for version {version}"))?;
|
|
||||||
|
|
||||||
sql.set_db_version_in_cache(version).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if dbversion < 109 {
|
if dbversion < 109 {
|
||||||
sql.execute_migration(
|
sql.execute_migration(
|
||||||
|
|||||||
BIN
test-data/core-1.86.0-backup.tar
Normal file
BIN
test-data/core-1.86.0-backup.tar
Normal file
Binary file not shown.
Reference in New Issue
Block a user