All rules Rule SL030 · OP
SQLite · alpha
warning
OP · Operational safety
free in the CLI — --engine=sqlite

ATTACH DATABASE in a migration

Warning — it works, but holds the single write lock or breaks the previous release.

What it catches

ATTACH opens a second database file on the runner's connection, by a path that only makes sense on one machine, for the life of that connection. In a migration it is almost always an import script that got committed: it fails on any other host, and while it works it can read from or write to a file the migration never declared.

Fires on

ATTACH DATABASE '/var/backups/legacy.db' AS legacy;
INSERT INTO orders SELECT * FROM legacy.orders;

Do this instead

Keep imports out of migrations: run them as an operational job with the file path as a parameter, and leave the migration to the schema.

-- operational import job, not a migration:
--    sqlite3 app.db "ATTACH '/path/legacy.db' AS legacy; INSERT INTO orders SELECT * FROM legacy.orders; DETACH legacy;"
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