refactor: Move logins into SQL table (#6724)

Move all `configured_*` parameters into a new SQL table `transports`.
All `configured_*` parameters are deprecated; the only exception is
`configured_addr`, which is used to store the address of the primary
transport. Currently, there can only ever be one primary transport (i.e.
the `transports` table only ever has one row); this PR is not supposed
to change DC's behavior in any meaningful way.

This is a preparation for mt.

---------

Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
Hocuri
2025-04-13 19:06:41 +02:00
committed by GitHub
parent 1722cb8851
commit 1379821b03
10 changed files with 364 additions and 145 deletions

View File

@@ -5,9 +5,11 @@ use deltachat_contact_tools::EmailAddress;
use rusqlite::OptionalExtension;
use crate::config::Config;
use crate::configure::EnteredLoginParam;
use crate::constants::ShowEmails;
use crate::context::Context;
use crate::imap;
use crate::login_param::ConfiguredLoginParam;
use crate::message::MsgId;
use crate::provider::get_provider_by_domain;
use crate::sql::Sql;
@@ -1186,6 +1188,42 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint);
.await?;
}
inc_and_check(&mut migration_version, 131)?;
if dbversion < migration_version {
let entered_param = EnteredLoginParam::load(context).await?;
let configured_param = ConfiguredLoginParam::load_legacy(context).await?;
sql.execute_migration_transaction(
|transaction| {
transaction.execute(
"CREATE TABLE transports (
id INTEGER PRIMARY KEY AUTOINCREMENT,
addr TEXT NOT NULL,
entered_param TEXT NOT NULL,
configured_param TEXT NOT NULL,
UNIQUE(addr)
)",
(),
)?;
if let Some(configured_param) = configured_param {
transaction.execute(
"INSERT INTO transports (addr, entered_param, configured_param)
VALUES (?, ?, ?)",
(
configured_param.addr.clone(),
serde_json::to_string(&entered_param)?,
configured_param.into_json()?,
),
)?;
}
Ok(())
},
migration_version,
)
.await?;
}
let new_version = sql
.get_raw_config_int(VERSION_CFG)
.await?
@@ -1230,6 +1268,21 @@ impl Sql {
}
async fn execute_migration(&self, query: &str, version: i32) -> Result<()> {
self.execute_migration_transaction(
|transaction| {
transaction.execute_batch(query)?;
Ok(())
},
version,
)
.await
}
async fn execute_migration_transaction(
&self,
migration: impl Send + FnOnce(&mut rusqlite::Transaction) -> Result<()>,
version: i32,
) -> Result<()> {
self.transaction(move |transaction| {
let curr_version: String = transaction.query_row(
"SELECT IFNULL(value, ?) FROM config WHERE keyname=?;",
@@ -1239,7 +1292,7 @@ impl Sql {
let curr_version: i32 = curr_version.parse()?;
ensure!(curr_version < version, "Db version must be increased");
Self::set_db_version_trans(transaction, version)?;
transaction.execute_batch(query)?;
migration(transaction)?;
Ok(())
})