fix(sqlite): dedup clears old external id before canonical upsert

This commit is contained in:
2026-10-25 23:39:04 +01:00
parent d073922308
commit b96f03f86f
3 changed files with 173 additions and 0 deletions

View File

@@ -37,6 +37,14 @@ impl MovieDeduplicator for SqliteMovieDeduplicator {
.await
.map_err(crate::shared::map_sqlx_error)?;
// The old row still holds the external id (it is deleted last); release it
// so the canonical upsert does not violate UNIQUE(external_metadata_id).
sqlx::query("UPDATE movies SET external_metadata_id = NULL WHERE id = ?")
.bind(&old)
.execute(&mut *tx)
.await
.map_err(crate::shared::map_sqlx_error)?;
sqlx::query(
"INSERT INTO movies (id, external_metadata_id, title, release_year, director, poster_path)
VALUES (?, ?, ?, ?, ?, ?)