Browse Source

fix(db): allow the index migration to be reverted on MariaDB

pull/7678/head
BryanFRD 3 weeks ago
parent
commit
7c2cc4c43b
  1. 4
      migrations/mysql/2026-09-02-120000_add_indexes/down.sql
  2. 10
      migrations/mysql/2026-09-02-120000_add_indexes/up.sql

4
migrations/mysql/2026-09-02-120000_add_indexes/down.sql

@ -1,3 +1,7 @@
-- On MariaDB these indexes back the foreign keys created from the inline REFERENCES,
-- and dropping them is refused with error 1553 while the constraints are enforced.
SET FOREIGN_KEY_CHECKS = 0;
DROP INDEX idx_ciphers_user_uuid ON ciphers; DROP INDEX idx_ciphers_user_uuid ON ciphers;
DROP INDEX idx_ciphers_organization_uuid ON ciphers; DROP INDEX idx_ciphers_organization_uuid ON ciphers;
DROP INDEX idx_attachments_cipher_uuid ON attachments; DROP INDEX idx_attachments_cipher_uuid ON attachments;

10
migrations/mysql/2026-09-02-120000_add_indexes/up.sql

@ -1,6 +1,10 @@
-- archives.cipher_uuid is left out: it is declared as an explicit FOREIGN KEY, -- archives.cipher_uuid is left out: it is declared as an explicit FOREIGN KEY, so both
-- so InnoDB already maintains an index for it. Every other table below uses -- MySQL and MariaDB already maintain an index for it.
-- inline REFERENCES, which MySQL parses and ignores, so no index exists. --
-- Every other table below uses inline REFERENCES. MySQL parses and ignores those, so no
-- index exists there. MariaDB honours them and backs each one with an auto-named index,
-- which InnoDB drops once the named index below can serve the constraint. Both engines
-- therefore end up with exactly one index per column.
CREATE INDEX idx_ciphers_user_uuid ON ciphers (user_uuid); CREATE INDEX idx_ciphers_user_uuid ON ciphers (user_uuid);
CREATE INDEX idx_ciphers_organization_uuid ON ciphers (organization_uuid); CREATE INDEX idx_ciphers_organization_uuid ON ciphers (organization_uuid);
CREATE INDEX idx_attachments_cipher_uuid ON attachments (cipher_uuid); CREATE INDEX idx_attachments_cipher_uuid ON attachments (cipher_uuid);

Loading…
Cancel
Save