From 5b507d897eeafc4f2dad5eabe849bd44e1eb02b0 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Fri, 6 Mar 2026 22:30:37 -0800 Subject: [PATCH] Fix similar_artists repair when profile_id column was previously stripped --- database/music_database.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/database/music_database.py b/database/music_database.py index ec1a2804..21862129 100644 --- a/database/music_database.py +++ b/database/music_database.py @@ -1846,16 +1846,27 @@ class MusicDatabase: """Fix similar_artists UNIQUE constraint and make discovery_pool_metadata per-profile (v3 migration)""" try: cursor.execute("SELECT value FROM metadata WHERE key = 'profiles_migration_v3' LIMIT 1") - if cursor.fetchone(): - return # Already migrated + already_migrated = cursor.fetchone() is not None + + # Always check if similar_artists actually has profile_id column + # (an older bug could strip it even after v3 migration ran) + cursor.execute("PRAGMA table_info(similar_artists)") + sa_cols = [c[1] for c in cursor.fetchall()] + needs_repair = 'profile_id' not in sa_cols - logger.info("Applying profile support v3 migration...") + if already_migrated and not needs_repair: + return # Already migrated and table is intact + + if needs_repair: + logger.info("Repairing similar_artists table — profile_id column missing, rebuilding...") + else: + logger.info("Applying profile support v3 migration...") # Rebuild similar_artists: UNIQUE(profile_id, source_artist_id, similar_artist_name) try: cursor.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name='similar_artists'") create_sql = cursor.fetchone() - if create_sql and 'UNIQUE(profile_id' not in create_sql[0]: + if create_sql and ('UNIQUE(profile_id' not in create_sql[0] or needs_repair): cursor.execute("PRAGMA table_info(similar_artists)") old_cols = [c[1] for c in cursor.fetchall()]