SQLite · alpha
note
TX · Transactions
free in the CLI — --engine=sqlite
Write migration in a DEFERRED transaction
Note — this works, but it is a documented trap or a cost the author may not have meant.
What it catches
A plain BEGIN is DEFERRED: it takes no lock until the first write, then tries to upgrade a read lock to a write lock. If another connection holds the write lock at that moment the upgrade fails immediately with SQLITE_BUSY — busy_timeout does not apply to a lock upgrade — and the migration aborts part way through its reads.
Fires on
BEGIN;
ALTER TABLE orders ADD COLUMN region TEXT;
COMMIT;Do this instead
Start a migration that writes with BEGIN IMMEDIATE: the write lock is taken up front, busy_timeout applies, and there is no upgrade to fail.
BEGIN IMMEDIATE;
ALTER TABLE orders ADD COLUMN region TEXT;
COMMIT;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