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,13 +1,13 @@
-- no-transaction
-- #73. movies.state used missing|grabbed|imported, predating arr-core's
-- canonical MediaState vocabulary (missing|downloading|available) that
-- series/episodes (0005) already follow.
--
-- SQLite can't ALTER a CHECK constraint, so this rebuilds the table. It runs
-- outside a transaction (#155) so `PRAGMA foreign_keys = OFF` takes effect
-- and dropping the old `movies` does not cascade into `movie_releases`.
-- SQLite can't ALTER a CHECK constraint, so this rebuilds the table -- which
-- means dropping the old copy. `movie_releases` references it with
-- ON DELETE CASCADE, so the drop would take its rows down too; stash them
-- first and restore them once the new `movies` exists with the same ids.
PRAGMA foreign_keys = OFF;
CREATE TABLE movie_releases_backup AS SELECT * FROM movie_releases;
CREATE TABLE movies_new (
id INTEGER PRIMARY KEY,
@@ -68,4 +68,6 @@ BEGIN
SELECT RAISE(ABORT, 'movies require a movie root');
END;
PRAGMA foreign_keys = ON;
INSERT INTO movie_releases SELECT * FROM movie_releases_backup;
DROP TABLE movie_releases_backup;