Follow-up fix for db migration issue (#956)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 6 Dec 2023 22:25:04 +0000 (23:25 +0100)
committerGitHub <noreply@github.com>
Wed, 6 Dec 2023 22:25:04 +0000 (23:25 +0100)
* Ignore albumless tracks in mb lookups

* fix db migration of radios and playlists tables

music_assistant/constants.py
music_assistant/server/controllers/music.py
music_assistant/server/providers/musicbrainz/__init__.py

index 2707afb09deb73d571953c8557c6f17008273f81..ea64aa717bdc86905b8d373bce36b786d055590c 100755 (executable)
@@ -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"
 
index 3076106aef99f30c05e76d7652d4ff995f897f84..34f5e1196eb3a83b5cbd2f7736f1ed1c0c563dea 100755 (executable)
@@ -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
index 392533659eb411a72b7eeffbe863995839601929..ec7ce03b84da75b7ba3bf8789721ded0ee121451 100644 (file)
@@ -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,