SQLite · alpha
note
CN · Constraints & keys
free in the CLI — --engine=sqlite
Foreign keys re-enabled without a foreign_key_check
Note — this works, but it is a documented trap or a cost the author may not have meant.
What it catches
Turning foreign keys back on does not validate what happened while they were off. Step 10 of the SQLite rebuild recipe is PRAGMA foreign_key_check before COMMIT — without it, an orphaned row created during the rebuild is discovered by the first user query that joins on it.
Fires on
PRAGMA foreign_keys = OFF;
BEGIN;
DROP TABLE orders;
ALTER TABLE orders_new RENAME TO orders;
COMMIT;
PRAGMA foreign_keys = ON;Do this instead
Run PRAGMA foreign_key_check inside the transaction, before COMMIT, so a violation can still be rolled back.
PRAGMA foreign_keys = OFF;
BEGIN;
DROP TABLE orders;
ALTER TABLE orders_new RENAME TO orders;
PRAGMA foreign_key_check;
COMMIT;
PRAGMA foreign_keys = ON;Catch this before it ships
SQLite support is in alpha: this rule runs locally in the free CLI, static only, and not in the hosted service yet: npx bolvrk check migration.sql --engine=sqlite