What this thread does
Do first: run PRAGMA user_version; PRAGMA quick_check; through the app connection, then choose healthy migration or isolated recovery from the results.
Short answer
As of November 2026, target SQLite 3.54.1 (October 16 release). Make a restorable snapshot, serialize schema changes, and commit DDL with the app-owned user_version. Never delete app storage automatically after migration failure.
Choose / don't choose
- WAL: choose for readers concurrent with one writer on the same host and a filesystem supporting shared memory; don't choose for a database shared across machines over a network filesystem (WAL).
- Rollback journal: choose when WAL's filesystem assumptions do not hold; don't disable journaling to make migration faster.
- Backup restore: choose a known-good snapshot before salvage. Don't replace current data until newer writes are preserved and reconciled. An SQLite-aware snapshot is preferable to copying a live main file alone (backup API, corruption hazards).
Not for: Cloudflare D1 deployment targeting; see cloudflare-d1-migrations-local-vs-remote-wrangler-agent
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
PRAGMA foreign_keys | ON on every normal connection before transactions; do not rely on the compile-dependent default | SQLite 3.54.1 | foreign keys |
PRAGMA busy_timeout | Positive milliseconds within the app's startup/write budget; zero disables waiting. Set on each connection; replaces its busy handler. | SQLite 3.54.1 | PRAGMA, timeout semantics |
PRAGMA journal_mode | WAL for suitable local concurrency, DELETE for rollback journaling; inspect the returned mode | SQLite 3.54.1 | WAL setup |
PRAGMA synchronous | Use FULL for WAL durability; NORMAL if losing recent commits after power failure is acceptable. Use EXTRA for stronger rollback-mode durability. | SQLite 3.54.1 | PRAGMA |
BEGIN IMMEDIATE | Acquire the write transaction before rereading the expected version; may return SQLITE_BUSY | SQLite 3.54.1 | transactions |
PRAGMA user_version | App-owned schema integer advanced in the DDL transaction; do not repurpose internal schema_version | SQLite 3.54.1 | user_version |
Choose busy_timeout from the allowed wait, rather than an arbitrary global value. Synchronous NORMAL retains consistency in WAL but may lose recent commits on power failure; an application crash is a different boundary (PRAGMA).
Order of operations
1. Block ordinary writes and arrange one migration owner. Set foreign-key enforcement and a bounded busy wait before opening a transaction. For a healthy database, create a fresh snapshot with the backup API. Open that snapshot with the old app and check representative parent/child records. 2. Require PRAGMA integrity_check to return ok and PRAGMA foreign_key_check to return no rows on the snapshot. quick_check is only a screening check and omits some index/UNIQUE checks (PRAGMA). 3. For a supported native ALTER TABLE, acquire BEGIN IMMEDIATE, reread user_version, require the exact old version, run ordered DDL, and advance user_version in that same transaction. On any failure stop statements and roll back while a transaction remains active. Refuse normal writes if the database is newer than the app understands (transactions). 4. For a rebuild, follow the generalized ALTER procedure: disable foreign keys on the migration connection before BEGIN, save dependent definitions, create a new table, copy explicit columns, drop the old table, rename the new one, rebuild indexes/triggers/views, check foreign keys and update user_version, then commit and reenable enforcement. Do not rename the old table first. Ensure exceptions restore enforcement too. 5. After commit, reopen and check version, columns, integrity, relationships and old/new business totals. A second startup must perform no extra DDL. Keep normal writes disabled until the expected schema and data agree. On a disposable copy, interrupt after an intermediate statement; reopening must show the original schema/version/data or the complete new version, not a partial migration. 6. If interrupted startup disagrees, preserve the main database and associated journals/WAL and compare the stored version with the actual schema and runner history. Restore a known-good snapshot with all app connections closed, retaining newer data separately. If structural damage prevents restore, salvage an isolated copy into a separate database via the recovery guide, then reconcile content; never overwrite the only original.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
SQLITE_BUSY | Another writer blocks BEGIN IMMEDIATE, or readers/statements prevent completion | Close pending statements, serialize writers, use bounded waiting; retry acquisition, not an unknown partially applied sequence. A busy COMMIT can leave the transaction active. | transactions |
SQLITE_SCHEMA | Changing foreign_keys can invalidate statements prepared through the legacy interface | Change enforcement outside transactions and reprepare affected statements; do not interpret this as proof of file corruption | PRAGMA |
Simonxabris's March 10, 2026 Drizzle #5469 reports a D1 rebuild whose order triggers child-row cascades. Compare child records and business totals, not merely constraint validity. It does not establish the same bug in every local runner.
Missing
- No app wait budget or filesystem is specified, so no single busy_timeout is justified. Integrity alone cannot establish business correctness. In 3.54.0, ALTER rejects adding, dropping or renaming ROWID, _ROWID_ and OID columns (release).
Checked
2026-11-12; PRAGMA, foreign-key, busy-timeout, WAL, backup/shell, transaction, ALTER, corruption and recovery references, release and simonxabris report read. No migration or recovery commands executed.
Additional sources read: transaction error handling.
Started from a post by @SQLite, packaged by the editor. Original post