fix(db): drop 0.8 rebuild workarounds, enforce title
With sqlx 0.9 honouring `-- no-transaction`, 0007 loses its movie_releases_backup stash like 0014 did, and 0021 gains the CHECK (title <> '') that #153 abandoned because the 0.8 migrator could not run a rebuild with foreign keys off. The rebuild test now enters at migration 6 so the child links ride through all three rebuilds, and a new test proves the '' -> 'TBA' backfill and the rejection of new empty titles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -336,7 +336,7 @@ mod tests {
|
||||
assert_eq!(renamed_from_imported, "available");
|
||||
}
|
||||
|
||||
/// #155: migration 0014 rebuilds `movies` and `episodes` outside a
|
||||
/// #155: the table-rebuild migrations (0007, 0014, 0021) run outside a
|
||||
/// transaction so `PRAGMA foreign_keys = OFF` holds and dropping the old
|
||||
/// tables does not cascade-delete `movie_releases`/`episode_releases`.
|
||||
#[tokio::test]
|
||||
@@ -347,9 +347,9 @@ mod tests {
|
||||
.expect("connect");
|
||||
|
||||
MIGRATOR
|
||||
.run_to(13, db.pool())
|
||||
.run_to(6, db.pool())
|
||||
.await
|
||||
.expect("migrations before the 0014 rebuild");
|
||||
.expect("migrations before the first rebuild");
|
||||
|
||||
sqlx::query(
|
||||
"INSERT INTO movies (tmdb_id, title, root_id)
|
||||
@@ -419,6 +419,55 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// #153: an empty episode title takes the TBA placeholder during 0021's
|
||||
/// backfill, and the rebuilt table's CHECK rejects new empty titles.
|
||||
#[tokio::test]
|
||||
async fn empty_episode_titles_are_backfilled_and_then_rejected() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let db = Db::connect(dir.path().join("arr.db"))
|
||||
.await
|
||||
.expect("connect");
|
||||
|
||||
MIGRATOR
|
||||
.run_to(20, db.pool())
|
||||
.await
|
||||
.expect("migrations before the #153 backfill");
|
||||
|
||||
let series_id = sqlx::query(
|
||||
"INSERT INTO series (tmdb_id, title, root_id)
|
||||
SELECT 82728, 'Bluey', id FROM roots WHERE kind = 'tv' LIMIT 1",
|
||||
)
|
||||
.execute(db.pool())
|
||||
.await
|
||||
.expect("series")
|
||||
.last_insert_rowid();
|
||||
let season_id = sqlx::query("INSERT INTO seasons (series_id, number) VALUES (?, 1)")
|
||||
.bind(series_id)
|
||||
.execute(db.pool())
|
||||
.await
|
||||
.expect("season")
|
||||
.last_insert_rowid();
|
||||
sqlx::query("INSERT INTO episodes (season_id, number, title) VALUES (?, 1, '')")
|
||||
.bind(season_id)
|
||||
.execute(db.pool())
|
||||
.await
|
||||
.expect("empty title, valid before 0021");
|
||||
|
||||
db.migrate().await.expect("remaining migrations");
|
||||
|
||||
let title: String = sqlx::query_scalar("SELECT title FROM episodes")
|
||||
.fetch_one(db.pool())
|
||||
.await
|
||||
.expect("episode row survives the rebuild");
|
||||
assert_eq!(title, "TBA");
|
||||
|
||||
sqlx::query("INSERT INTO episodes (season_id, number, title) VALUES (?, 2, '')")
|
||||
.bind(season_id)
|
||||
.execute(db.pool())
|
||||
.await
|
||||
.expect_err("the rebuilt column rejects the empty string");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn seeds_two_tv_roots_with_distinct_policies() {
|
||||
let (_dir, db) = fresh().await;
|
||||
|
||||
Reference in New Issue
Block a user