Add the episode title CHECK as a new migration #178

Open
opened 2026-08-24 19:20:31 +01:00 by naps62-yolo · 0 comments
Owner

CHECK (title <> '') on episodes.title is not in place. It was originally
abandoned in #153 because sqlx 0.8 made the table rebuild cascade-delete
children, then re-added by #155 as an in-place edit to migration
0021_episode_title_required.sql.

That edit had to be reverted. Changing an already-applied migration changes its
checksum, and migrate() refuses to start when one no longer matches what
_sqlx_migrations recorded — the daemon exited on boot against production and
the site was down for about ten minutes. See commit a3897df.

The constraint is still worth having, and now it can actually be added: the
sqlx 0.9 bump from #155 stands, so a migration marked -- no-transaction
holds PRAGMA foreign_keys = OFF across the rebuild and children survive.

Add it as a new migration on top rather than by editing 0021:

  • backfill any empty episodes.title to the TBA placeholder 0021 already uses
  • rebuild episodes with the CHECK, under -- no-transaction
  • assert in a test that episode_releases rows survive the rebuild, the way
    table_rebuild_preserves_child_rows does

The test empty_episode_titles_are_backfilled_and_then_rejected was removed
along with the reverted edit; restore it against the new migration.

Never edit a migration that has already run. Every schema change is a new
file. This is the second time the rule has cost something — #153 lost the
constraint, #155 lost production availability.

`CHECK (title <> '')` on `episodes.title` is not in place. It was originally abandoned in #153 because sqlx 0.8 made the table rebuild cascade-delete children, then re-added by #155 as an in-place edit to migration `0021_episode_title_required.sql`. That edit had to be reverted. Changing an already-applied migration changes its checksum, and `migrate()` refuses to start when one no longer matches what `_sqlx_migrations` recorded — the daemon exited on boot against production and the site was down for about ten minutes. See commit `a3897df`. The constraint is still worth having, and now it can actually be added: the sqlx 0.9 bump from #155 stands, so a migration marked `-- no-transaction` holds `PRAGMA foreign_keys = OFF` across the rebuild and children survive. Add it as a **new** migration on top rather than by editing `0021`: - backfill any empty `episodes.title` to the TBA placeholder `0021` already uses - rebuild `episodes` with the CHECK, under `-- no-transaction` - assert in a test that `episode_releases` rows survive the rebuild, the way `table_rebuild_preserves_child_rows` does The test `empty_episode_titles_are_backfilled_and_then_rejected` was removed along with the reverted edit; restore it against the new migration. **Never edit a migration that has already run.** Every schema change is a new file. This is the second time the rule has cost something — #153 lost the constraint, #155 lost production availability.
naps62-yolo added the area/dbdifficulty/moderatetype/bug labels 2026-08-24 19:20:31 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yolo/arr#178