From df14bbf745da1b5ecb6a2c2a947d0aa4de965861 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Fri, 10 Apr 2026 10:45:47 -0700 Subject: [PATCH] Add one-time migration to purge stale Deezer metadata cache Deezer album entries cached from /artist/{id}/albums lack artist info, and track entries from search results lack track_position. Purges all Deezer album/track cache entries on first startup so they repopulate with complete data. --- database/music_database.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/database/music_database.py b/database/music_database.py index 2f176efb..fe6cbb2f 100644 --- a/database/music_database.py +++ b/database/music_database.py @@ -568,6 +568,23 @@ class MusicDatabase: except Exception: pass + # One-time migration: purge Deezer album/track cache entries with missing data. + # Deezer's /artist/{id}/albums returns albums without artist info, and search + # results cache tracks without track_position — both produce bad metadata. + try: + cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='_deezer_cache_v2_migrated'") + if not cursor.fetchone(): + cursor.execute("""DELETE FROM metadata_cache_entities + WHERE source = 'deezer' AND entity_type IN ('album', 'track')""") + purged = cursor.rowcount + cursor.execute("""DELETE FROM metadata_cache_searches + WHERE source = 'deezer' AND search_type IN ('album', 'track')""") + cursor.execute("CREATE TABLE _deezer_cache_v2_migrated (applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)") + if purged > 0: + logger.info(f"Purged {purged} stale Deezer cache entries (missing artist/track_position)") + except Exception: + pass + conn.commit() logger.info("Database initialized successfully")