From 495195166670c9c1f199fa5342541c7a1f2227ae Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 6 Dec 2023 23:25:04 +0100 Subject: [PATCH] Follow-up fix for db migration issue (#956) * Ignore albumless tracks in mb lookups * fix db migration of radios and playlists tables --- music_assistant/constants.py | 2 +- music_assistant/server/controllers/music.py | 21 ++++++++++++++++++- .../server/providers/musicbrainz/__init__.py | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/music_assistant/constants.py b/music_assistant/constants.py index 2707afb0..ea64aa71 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -5,7 +5,7 @@ from typing import Final API_SCHEMA_VERSION: Final[int] = 23 MIN_SCHEMA_VERSION: Final[int] = 23 -DB_SCHEMA_VERSION: Final[int] = 26 +DB_SCHEMA_VERSION: Final[int] = 27 ROOT_LOGGER_NAME: Final[str] = "music_assistant" diff --git a/music_assistant/server/controllers/music.py b/music_assistant/server/controllers/music.py index 3076106a..34f5e119 100755 --- a/music_assistant/server/controllers/music.py +++ b/music_assistant/server/controllers/music.py @@ -646,7 +646,7 @@ class MusicController(CoreController): await asyncio.to_thread(shutil.copyfile, db_path, db_path_backup) # handle db migration from previous schema to this one - if prev_version == DB_SCHEMA_VERSION - 1: + if prev_version == 25: self.logger.info( "Performing database migration from %s to %s", prev_version, @@ -658,6 +658,8 @@ class MusicController(CoreController): DB_TABLE_ARTISTS, DB_TABLE_ALBUMS, DB_TABLE_TRACKS, + DB_TABLE_PLAYLISTS, + DB_TABLE_RADIOS, ): # create new external_ids column await self.database.execute( @@ -693,6 +695,23 @@ class MusicController(CoreController): "Database migration to version %s completed", DB_SCHEMA_VERSION, ) + elif prev_version == 26: + self.logger.info( + "Performing database migration from %s to %s", + prev_version, + DB_SCHEMA_VERSION, + ) + # migrate playlists and radios tables which we forgot to migrate in schema 26 + for table in ( + DB_TABLE_PLAYLISTS, + DB_TABLE_RADIOS, + ): + # create new external_ids column + await self.database.execute( + f"ALTER TABLE {table} " + "ADD COLUMN external_ids " + "json NOT NULL DEFAULT '[]'" + ) # handle all other schema versions else: # we keep it simple and just recreate the tables diff --git a/music_assistant/server/providers/musicbrainz/__init__.py b/music_assistant/server/providers/musicbrainz/__init__.py index 39253365..ec7ce03b 100644 --- a/music_assistant/server/providers/musicbrainz/__init__.py +++ b/music_assistant/server/providers/musicbrainz/__init__.py @@ -223,6 +223,8 @@ class MusicbrainzProvider(MetadataProvider): return mb_artist.id # last restort: track matching by name for ref_track in ref_tracks: + if not ref_track.album: + continue if result := await self.search( artistname=artist.name, albumname=ref_track.album.name, -- 2.34.1