feat(db): align movie state with canonical MediaState (#85)
ci / web (push) Successful in 29s
e2e / e2e (push) Successful in 47s
ci / rust (push) Successful in 2m59s

This commit was merged in pull request #85.
This commit is contained in:
2026-08-22 23:21:09 +01:00
parent d3cea8693b
commit 62aba6315c
5 changed files with 143 additions and 14 deletions
+56
View File
@@ -252,6 +252,62 @@ mod tests {
.expect_err("state is a closed set");
}
/// #73: migration 0007 renames the pre-canonical `grabbed`/`imported`
/// values in place rather than dropping the rows that held them.
#[tokio::test]
async fn movie_state_migration_renames_existing_rows_in_place() {
let dir = tempfile::tempdir().expect("tempdir");
let db = Db::connect(dir.path().join("arr.db"))
.await
.expect("connect");
let pre_0007 = sqlx::migrate::Migrator {
migrations: std::borrow::Cow::Owned(
MIGRATOR.iter().filter(|m| m.version < 7).cloned().collect(),
),
ignore_missing: MIGRATOR.ignore_missing,
locking: MIGRATOR.locking,
no_tx: MIGRATOR.no_tx,
};
pre_0007
.run(db.pool())
.await
.expect("migrations before #73");
sqlx::query(
"INSERT INTO movies (tmdb_id, title, root_id, state)
SELECT 1, 'Old Vocabulary', id, 'grabbed' FROM roots WHERE kind = 'movie' LIMIT 1",
)
.execute(db.pool())
.await
.expect("legacy 'grabbed' row, valid under the pre-#73 constraint");
sqlx::query(
"INSERT INTO movies (tmdb_id, title, root_id, state)
SELECT 2, 'Also Old', id, 'imported' FROM roots WHERE kind = 'movie' LIMIT 1",
)
.execute(db.pool())
.await
.expect("legacy 'imported' row, valid under the pre-#73 constraint");
db.migrate()
.await
.expect("remaining migrations, including #73");
let renamed_from_grabbed: String =
sqlx::query_scalar("SELECT state FROM movies WHERE tmdb_id = 1")
.fetch_one(db.pool())
.await
.expect("row survives the migration");
let renamed_from_imported: String =
sqlx::query_scalar("SELECT state FROM movies WHERE tmdb_id = 2")
.fetch_one(db.pool())
.await
.expect("row survives the migration");
assert_eq!(renamed_from_grabbed, "downloading");
assert_eq!(renamed_from_imported, "available");
}
#[tokio::test]
async fn seeds_two_tv_roots_with_distinct_policies() {
let (_dir, db) = fresh().await;