Skip to content

Commit 126c64f

Browse files
Hocurilink2xt
authored andcommitted
fix: Make pre-messages db migration backwards-compatible
See this comment that described the problem: https://github.com/chatmail/core/pull/7371/files#r2612182387 > The migration removes the `msg_id` column from the `download` table, so that, if you import the backup into an older DC version, you get the error `Failed inbox fetch_idle: Failed to download messages: no such column: msg_id in SELECT msg_id FROM download at offset 7: Error code 1: SQL error or missing database.` > > So, we need: > - either to make sure that things somewhat work if the user downgrades > - or to again increase `backup_version`, and then again coordinate that releases are done on all platforms simultaneously (which I would like to avoid). This PR here implements the first solution: Re-add `download.msg_id`, so that an older core can handle the database scheme.
1 parent 07de9ac commit 126c64f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl MsgId {
8282
context
8383
.sql
8484
.execute(
85-
"INSERT INTO download (rfc724_mid) VALUES (?)",
86-
(msg.rfc724_mid(),),
85+
"INSERT INTO download (rfc724_mid, msg_id) VALUES (?,?)",
86+
(msg.rfc724_mid(), msg.id),
8787
)
8888
.await?;
8989
context.scheduler.interrupt_inbox().await;

src/imap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ impl Imap {
825825
context
826826
.sql
827827
.insert(
828-
"INSERT INTO download (rfc724_mid) VALUES (?)",
828+
"INSERT INTO download (rfc724_mid, msg_id) VALUES (?,0)",
829829
(rfc724_mid,),
830830
)
831831
.await?;

src/sql/migrations.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,12 +1506,16 @@ ORDER BY last_seen DESC LIMIT 10000
15061506

15071507
inc_and_check(&mut migration_version, 144)?;
15081508
if dbversion < migration_version {
1509+
// `msg_id` in `download` table is not needed anymore,
1510+
// but we still keep it so that it's possible to import a backup into an older DC version,
1511+
// because we don't always release at the same time on all platforms.
15091512
sql.execute_migration(
15101513
"CREATE TABLE download_new (
1511-
rfc724_mid TEXT NOT NULL
1514+
rfc724_mid TEXT NOT NULL DEFAULT '',
1515+
msg_id INTEGER NOT NULL DEFAULT 0
15121516
) STRICT;
1513-
INSERT OR IGNORE INTO download_new (rfc724_mid)
1514-
SELECT m.rfc724_mid FROM download d
1517+
INSERT OR IGNORE INTO download_new (rfc724_mid, msg_id)
1518+
SELECT m.rfc724_mid, d.msg_id FROM download d
15151519
JOIN msgs m ON d.msg_id = m.id
15161520
WHERE m.rfc724_mid IS NOT NULL AND m.rfc724_mid != '';
15171521
DROP TABLE download;

0 commit comments

Comments
 (0)