mirror of
https://github.com/axllent/mailpit.git
synced 2025-05-15 22:16:44 +02:00
This SQL patch rebuilds the message_tags table to remove the unused ID & TagID REFERENCES that was sometimes causing FOREIGN KEY errors when deleting messages (with tags) using the rqlite database. This is not a bug in rqlite, but rather a limitation of how Mailpit integrated with rqlite as an optional alternative database.
23 lines
811 B
SQL
23 lines
811 B
SQL
-- Rebuild message_tags to remove FOREIGN KEY REFERENCES
|
|
PRAGMA foreign_keys=OFF;
|
|
|
|
DROP INDEX IF EXISTS {{ tenant "idx_message_tag_id" }};
|
|
DROP INDEX IF EXISTS {{ tenant "idx_message_tag_tagid" }};
|
|
|
|
ALTER TABLE {{ tenant "message_tags" }} RENAME TO _{{ tenant "message_tags" }}_old;
|
|
|
|
CREATE TABLE IF NOT EXISTS {{ tenant "message_tags" }} (
|
|
Key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
ID TEXT NOT NULL,
|
|
TagID INTEGER NOT NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS {{ tenant "idx_message_tags_id" }} ON {{ tenant "message_tags" }} (ID);
|
|
CREATE INDEX IF NOT EXISTS {{ tenant "idx_message_tags_tagid" }} ON {{ tenant "message_tags" }} (TagID);
|
|
|
|
INSERT INTO {{ tenant "message_tags" }} SELECT * FROM _{{ tenant "message_tags" }}_old;
|
|
|
|
DROP TABLE IF EXISTS _{{ tenant "message_tags" }}_old;
|
|
|
|
PRAGMA foreign_keys=ON;
|