"Migrating database from version %s to %s", prev_version, DB_SCHEMA_VERSION
)
- if prev_version <= 9:
+ if prev_version < 7:
raise MusicAssistantError("Database schema version too old to migrate")
- if prev_version <= 10:
- # add new columns to playlog table
+ if prev_version <= 7:
+ # remove redundant artists and provider_mappings columns
+ for table in (
+ DB_TABLE_TRACKS,
+ DB_TABLE_ALBUMS,
+ DB_TABLE_ARTISTS,
+ DB_TABLE_RADIOS,
+ DB_TABLE_PLAYLISTS,
+ ):
+ for column in ("artists", "provider_mappings"):
+ try:
+ await self.database.execute(f"ALTER TABLE {table} DROP COLUMN {column}")
+ except Exception as err:
+ if "no such column" in str(err):
+ continue
+ raise
+ # add cache_checksum column to playlists
try:
await self.database.execute(
- f"ALTER TABLE {DB_TABLE_PLAYLOG} ADD COLUMN fully_played BOOLEAN"
- )
- await self.database.execute(
- f"ALTER TABLE {DB_TABLE_PLAYLOG} ADD COLUMN seconds_played INTEGER"
+ f"ALTER TABLE {DB_TABLE_PLAYLISTS} ADD COLUMN cache_checksum TEXT DEFAULT ''"
)
except Exception as err:
if "duplicate column" not in str(err):
raise
+ if prev_version <= 8:
+ # migrate track_loudness --> loudness_measurements
+ async for db_row in self.database.iter_items("track_loudness"):
+ if db_row["integrated"] == inf or db_row["integrated"] == -inf:
+ continue
+ if db_row["provider"] in ("radiobrowser", "tunein"):
+ continue
+ await self.database.insert_or_replace(
+ DB_TABLE_LOUDNESS_MEASUREMENTS,
+ {
+ "item_id": db_row["item_id"],
+ "media_type": "track",
+ "provider": db_row["provider"],
+ "loudness": db_row["integrated"],
+ },
+ )
+ await self.database.execute("DROP TABLE IF EXISTS track_loudness")
+
+ if prev_version <= 10:
+ # Recreate playlog table due to complete new layout
+ await self.database.execute(f"DROP TABLE IF EXISTS {DB_TABLE_PLAYLOG}")
+ await self.__create_database_tables()
+
if prev_version <= 12:
# Need to drop the NOT NULL requirement on podcasts.publisher and audiobooks.publisher
# However, because there is no ALTER COLUMN support in sqlite, we will need