Fix SQL schema issues across all database engines

- Increase password column from varchar(64) to varchar(255) to
  prevent silent truncation of encrypted passwords
- Add missing UNIQUE constraint on iid in MySQL
- Add missing IX_ident_switch_iid index in PostgreSQL
- Remove deprecated int display width in MySQL (int(10) -> int)
- Fix trailing comma syntax error in SQLite 2018121800 migration
- Normalize indentation across all initial SQL files
- Add migration 2026021000 for all engines to fix existing installs
This commit is contained in:
Laurent Dinclaux
2026-02-10 10:35:20 +11:00
parent 958af7769f
commit 3c4d856d60
7 changed files with 113 additions and 31 deletions

View File

@@ -1,19 +1,20 @@
CREATE TABLE IF NOT EXISTS `ident_switch`
(
`id`
int(10) UNSIGNED
int UNSIGNED
NOT NULL
AUTO_INCREMENT,
`user_id`
int(10) UNSIGNED
int UNSIGNED
NOT NULL,
`iid`
int(10) UNSIGNED
NOT NULL,
int UNSIGNED
NOT NULL
UNIQUE,
`username`
varchar(64),
`password`
varchar(64),
varchar(255),
`imap_host`
varchar(64),
`imap_port`
@@ -51,4 +52,3 @@ CREATE TABLE IF NOT EXISTS `ident_switch`
INDEX `IX_ident_switch_user_id`(`user_id`),
INDEX `IX_ident_switch_iid`(`iid`)
);

5
SQL/mysql/2026021000.sql Normal file
View File

@@ -0,0 +1,5 @@
ALTER TABLE `ident_switch`
MODIFY `password` varchar(255);
ALTER TABLE `ident_switch`
ADD UNIQUE (`iid`);

View File

@@ -15,7 +15,7 @@ CREATE TABLE ident_switch
username
varchar(64),
password
varchar(64),
varchar(255),
imap_host
varchar(64),
imap_port
@@ -49,7 +49,5 @@ CREATE TABLE ident_switch
UNIQUE (user_id, label)
);
CREATE INDEX
IX_ident_switch_user_id
ON
ident_switch(user_id);
CREATE INDEX IX_ident_switch_user_id ON ident_switch(user_id);
CREATE INDEX IX_ident_switch_iid ON ident_switch(iid);

View File

@@ -0,0 +1,4 @@
ALTER TABLE ident_switch
ALTER COLUMN password TYPE varchar(255);
CREATE INDEX IF NOT EXISTS IX_ident_switch_iid ON ident_switch(iid);

View File

@@ -15,7 +15,7 @@ CREATE TABLE ident_switch
username
varchar(64),
password
varchar(64),
varchar(255),
imap_host
varchar(64),
imap_port
@@ -49,4 +49,4 @@ CREATE TABLE ident_switch
UNIQUE (user_id, label)
);
CREATE INDEX IX_ident_switch_user_id ON ident_switch(user_id);
CREATE INDEX IX_ident_switch_iid on ident_switch(iid);
CREATE INDEX IX_ident_switch_iid ON ident_switch(iid);

View File

@@ -65,7 +65,7 @@ SELECT
port,
label,
flags,
host,
host
FROM
ident_switch_old;

75
SQL/sqlite/2026021000.sql Normal file
View File

@@ -0,0 +1,75 @@
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
ALTER TABLE ident_switch RENAME TO ident_switch_old;
CREATE TABLE ident_switch
(
id
integer
PRIMARY KEY,
user_id
integer
NOT NULL
REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE,
iid
integer
NOT NULL
REFERENCES identities(identity_id) ON DELETE CASCADE ON UPDATE CASCADE
UNIQUE,
username
varchar(64),
password
varchar(255),
imap_host
varchar(64),
imap_port
integer
CHECK(imap_port > 0 AND imap_port <= 65535),
imap_delimiter
char(1),
label
varchar(32),
flags
integer
NOT NULL
DEFAULT(0),
smtp_host
varchar(64),
smtp_port
integer
CHECK(smtp_port > 0 AND smtp_port <= 65535),
smtp_auth
smallint
NOT NULL
DEFAULT 1,
drafts_mbox
varchar(64),
sent_mbox
varchar(64),
junk_mbox
varchar(64),
trash_mbox
varchar(64),
UNIQUE (user_id, label)
);
CREATE INDEX IX_ident_switch_user_id ON ident_switch(user_id);
CREATE INDEX IX_ident_switch_iid ON ident_switch(iid);
INSERT OR ROLLBACK INTO
ident_switch (
id, user_id, iid, username, password, imap_host, imap_port,
imap_delimiter, label, flags, smtp_host, smtp_port, smtp_auth,
drafts_mbox, sent_mbox, junk_mbox, trash_mbox
)
SELECT
id, user_id, iid, username, password, imap_host, imap_port,
imap_delimiter, label, flags, smtp_host, smtp_port, smtp_auth,
drafts_mbox, sent_mbox, junk_mbox, trash_mbox
FROM
ident_switch_old;
DROP TABLE ident_switch_old;
COMMIT;
PRAGMA foreign_keys=on;