SQLite state file may be partially written after interrupted Reflex 0.5.0 migration
0 reputation · 04 Apr 2021, 15:17 UTC
0 reputation · 04 Apr 2021, 15:17 UTC
When upgrading a Reflex application from a version that used in‑memory state to Reflex 0.5.0, the framework expects a SQLite database at the location previously used for state storage. The supplied reflex migrate-state command copies the existing in‑memory state into this new file, but the operation is not wrapped in a transaction. If the migration is halted—by a power loss, process kill, or user interruption—the SQLite file can be left partially written or corrupted. On the next start, Reflex treats this as a fatal error and fails to launch, with no automatic rollback to the previous in‑memory state.
What mechanisms, if any, does Reflex provide to detect a partially written SQLite state file after an interrupted migration?
Should users rely solely on pre‑migration backups and integrity checks, or is there a preferred automated fallback strategy?
Is there a plan to make the migration command transactional or to introduce an automatic rollback mechanism in a future release?
29775 reputation · 04 Apr 2021, 21:20 UTC
Reflex does not add its own detection or automatic rollback for a partially written SQLite state file. You must rely on SQLite’s built‑in atomicity guarantees and run a manual integrity check after an interruption.
The reflex migrate-state command copies in‑memory state into a new SQLite file without wrapping the copy in an explicit transaction. If the process is killed before the copy finishes, SQLite’s journaling (rollback journal or WAL) may contain uncommitted changes, but the main database file usually remains unchanged until a commit occurs. On the next open SQLite will roll back any incomplete transaction unless the journal files are missing or damaged.
PRAGMA integrity_check; will report any structural corruption.-journal, -wal, or -shm files indicates an interrupted transaction that SQLite will handle on next open.state.sqlite) and any companion files (state.sqlite-journal, state.sqlite-wal, state.sqlite-shm).sqlite3 state.sqlite "PRAGMA integrity_check;"
ok, the database is structurally sound and can be used; you may safely delete the journal/WAL files if they persist.reflex migrate-state.sqlite3 state.sqlite "SELECT 1;"
There is no automated fallback inside Reflex. The recommended practice is to keep a backup of the pre‑migration state file (or the in‑memory state snapshot) and rely on the integrity check described above. If the check fails, restore from backup and retry the migration.
As of Reflex 0.5.0, the migration command is not transactional and there is no announced plan to add automatic rollback. Users should monitor the project’s release notes for any changes that make the migration atomic.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.