Skip to content

Commit

Permalink
fix: recreate smtp table with AUTOINCREMENT
Browse files Browse the repository at this point in the history
This ensures the rows cannot be confused accidentally
when referred by row_id.

Also remove unused rfc724_mid column.
  • Loading branch information
link2xt committed May 10, 2023
1 parent b7bbb3e commit 37c2401
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Fixes
- Make the bots automatically accept group chat contact requests. #4377
- Fetch at most 100 existing messages even if EXISTS was not received. #4383
- Recreate `smtp` table with AUTOINCREMENT `id`. #4390

### Fixes
- jsonrpc: typescript client: fix types of events in event emitter
Expand Down
11 changes: 3 additions & 8 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2368,14 +2368,9 @@ async fn create_send_msg_job(context: &Context, msg_id: MsgId) -> Result<Option<
let row_id = context
.sql
.insert(
"INSERT INTO smtp (rfc724_mid, recipients, mime, msg_id)
VALUES (?1, ?2, ?3, ?4)",
(
&rendered_msg.rfc724_mid,
recipients,
&rendered_msg.message,
msg_id,
),
"INSERT INTO smtp (recipients, mime, msg_id)
VALUES (?1, ?2, ?3)",
(recipients, &rendered_msg.message, msg_id),
)
.await?;
Ok(Some(row_id))
Expand Down
16 changes: 16 additions & 0 deletions src/sql/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,22 @@ CREATE INDEX smtp_messageid ON imap(rfc724_mid);
)
.await?;
}
if dbversion < 101 {
// Recreate `smtp` table without `rfc724_mid` field and with autoincrement.
sql.execute_migration(
"DROP TABLE smtp;
CREATE TABLE smtp (
id INTEGER PRIMARY KEY AUTOINCREMENT,
mime TEXT NOT NULL, -- SMTP payload
msg_id INTEGER NOT NULL, -- ID of the message in `msgs` table
recipients TEXT NOT NULL, -- List of recipients separated by space
retries INTEGER NOT NULL DEFAULT 0 -- Number of failed attempts to send the message
);
",
101,
)
.await?;
}

let new_version = sql
.get_raw_config_int(VERSION_CFG)
Expand Down

0 comments on commit 37c2401

Please sign in to comment.