fix(db): keep migration checksums stable
ci / web (push) Successful in 38s
ci / rust (push) Successful in 1m4s
e2e / e2e (push) Successful in 1m14s

Issue #155 removed the sqlx 0.8 rebuild workarounds by editing migrations
0007, 0014 and 0021 in place. Editing an applied migration changes its
checksum, and `migrate()` refuses to run when one no longer matches what
`_sqlx_migrations` recorded, so the daemon exited on startup against any
database that had already applied them — production included.

The sqlx 0.9 bump is the fix and survives: a new migration can carry
`-- no-transaction` so `PRAGMA foreign_keys = OFF` holds and a table
rebuild stops cascade-deleting its children. Only the retroactive cleanup
of migrations that already ran is reverted, along with #153's
`CHECK (title <> '')`, which rode on the 0021 edit and needs a migration
of its own rather than a rewrite of history.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-08-24 19:14:42 +01:00
parent 83a0b247c9
commit a3897df0ab
4 changed files with 21 additions and 106 deletions
@@ -1,15 +1,11 @@
-- no-transaction
-- #108: a vanished torrent must not re-grab. Overrides #86, which reopened
-- the gap (state = 'missing', wanted untouched) so the next tick re-grabbed
-- the same release. Adds 'parked' so the daemon can clear `wanted` and mark
-- the title honestly instead — distinct from 'missing' (an open gap) and
-- 'available' (satisfied). SQLite cannot alter a CHECK, so both tables are
-- rebuilt (see 0007).
--
-- #155: runs outside a transaction so `PRAGMA foreign_keys = OFF` takes
-- effect and dropping the old tables does not cascade into their children.
PRAGMA foreign_keys = OFF;
CREATE TABLE movie_releases_backup AS SELECT * FROM movie_releases;
CREATE TABLE movies_new (
id INTEGER PRIMARY KEY,
@@ -67,6 +63,11 @@ BEGIN
SELECT RAISE(ABORT, 'movies require a movie root');
END;
INSERT INTO movie_releases SELECT * FROM movie_releases_backup;
DROP TABLE movie_releases_backup;
CREATE TABLE episode_releases_backup AS SELECT * FROM episode_releases;
CREATE TABLE episodes_new (
id INTEGER PRIMARY KEY,
season_id INTEGER NOT NULL REFERENCES seasons (id) ON DELETE CASCADE,
@@ -101,4 +102,5 @@ CREATE INDEX episodes_pending_search
CREATE INDEX episodes_state ON episodes (state);
PRAGMA foreign_keys = ON;
INSERT INTO episode_releases SELECT * FROM episode_releases_backup;
DROP TABLE episode_releases_backup;