Skip to content

Commit

Permalink
Follow-up fix for db migration issue (#956)
Browse files Browse the repository at this point in the history
* Ignore albumless tracks in mb lookups

* fix db migration of radios and playlists tables
  • Loading branch information
marcelveldt authored Dec 6, 2023
1 parent 866ad76 commit 4951951
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion music_assistant/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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"

Expand Down
21 changes: 20 additions & 1 deletion music_assistant/server/controllers/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ async def _setup_database(self):
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,
Expand All @@ -658,6 +658,8 @@ async def _setup_database(self):
DB_TABLE_ARTISTS,
DB_TABLE_ALBUMS,
DB_TABLE_TRACKS,
DB_TABLE_PLAYLISTS,
DB_TABLE_RADIOS,
):
# create new external_ids column
await self.database.execute(
Expand Down Expand Up @@ -693,6 +695,23 @@ async def _setup_database(self):
"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
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/server/providers/musicbrainz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ async def get_musicbrainz_artist_id(
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,
Expand Down

0 comments on commit 4951951

Please sign in to comment.