fix(db): keep migration checksums stable
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:
@@ -1,51 +1,11 @@
|
||||
-- no-transaction
|
||||
-- #153. `episodes.title` accepted the empty string, which TMDB sends for an
|
||||
-- unaired episode it has not named yet. Empty titles leaked into §9.2's
|
||||
-- search haystack, §7.4 filenames and the compat shim as if they were real
|
||||
-- text. Rows already carrying `''` take the same "TBA" placeholder the TMDB
|
||||
-- boundary now substitutes — #121's guarded update replaces it once TMDB
|
||||
-- fills the title in — and the rebuilt table enforces non-empty with a
|
||||
-- CHECK. The rebuild runs outside a transaction (#155) so
|
||||
-- `PRAGMA foreign_keys = OFF` takes effect and dropping the old `episodes`
|
||||
-- does not cascade into `episode_releases`.
|
||||
|
||||
-- fills the title in.
|
||||
--
|
||||
-- A hard CHECK (title <> '') would need a table rebuild with foreign_keys
|
||||
-- off, which sqlx 0.8's migrator cannot run (it always wraps a migration in
|
||||
-- a transaction, where that pragma is a no-op); enforcement lives in code.
|
||||
UPDATE episodes SET title = 'TBA', updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE title = '';
|
||||
|
||||
PRAGMA foreign_keys = OFF;
|
||||
|
||||
CREATE TABLE episodes_new (
|
||||
id INTEGER PRIMARY KEY,
|
||||
season_id INTEGER NOT NULL REFERENCES seasons (id) ON DELETE CASCADE,
|
||||
number INTEGER NOT NULL CHECK (number >= 0),
|
||||
title TEXT NOT NULL CHECK (title <> ''),
|
||||
air_date TEXT,
|
||||
wanted INTEGER NOT NULL DEFAULT 0 CHECK (wanted IN (0, 1)),
|
||||
state TEXT NOT NULL DEFAULT 'missing'
|
||||
CHECK (state IN ('missing', 'downloading', 'available', 'parked')),
|
||||
search_attempts INTEGER NOT NULL DEFAULT 0,
|
||||
last_searched_at TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
||||
vanished INTEGER NOT NULL DEFAULT 0 CHECK (vanished IN (0, 1)),
|
||||
UNIQUE (season_id, number)
|
||||
) STRICT;
|
||||
|
||||
INSERT INTO episodes_new (
|
||||
id, season_id, number, title, air_date, wanted, state, search_attempts,
|
||||
last_searched_at, created_at, updated_at, vanished
|
||||
)
|
||||
SELECT
|
||||
id, season_id, number, title, air_date, wanted, state, search_attempts,
|
||||
last_searched_at, created_at, updated_at, vanished
|
||||
FROM episodes;
|
||||
|
||||
DROP TABLE episodes;
|
||||
ALTER TABLE episodes_new RENAME TO episodes;
|
||||
|
||||
CREATE INDEX episodes_pending_search
|
||||
ON episodes (last_searched_at)
|
||||
WHERE wanted = 1 AND state = 'missing';
|
||||
|
||||
CREATE INDEX episodes_state ON episodes (state);
|
||||
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
Reference in New Issue
Block a user