Fix db error when migrating from old version (#368)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 16 Jun 2022 07:40:37 +0000 (09:40 +0200)
committerGitHub <noreply@github.com>
Thu, 16 Jun 2022 07:40:37 +0000 (09:40 +0200)
music_assistant/helpers/database.py

index 2541620fdfaa5fba06b3a00c378a241c14bd5927..dc44043396e61328ef9275e15b8d379aec21b315 100755 (executable)
@@ -220,7 +220,7 @@ class Database:
                 # always create db tables if they don't exist to prevent errors trying to access them later
                 await self.__create_database_tables(db)
 
-                if prev_version < 15:
+                if prev_version < 17:
                     # too many changes, just recreate
                     await db.execute(f"DROP TABLE IF EXISTS {TABLE_ARTISTS}")
                     await db.execute(f"DROP TABLE IF EXISTS {TABLE_ALBUMS}")
@@ -233,20 +233,6 @@ class Database:
                     # recreate missing tables
                     await self.__create_database_tables(db)
 
-                if prev_version and prev_version < 16:
-                    # album artist --> album artists
-                    await db.execute(f"ALTER TABLE {TABLE_ALBUMS} ADD artists json;")
-                    for db_row in await self.get_rows(TABLE_ALBUMS, db=db):
-                        match = {"item_id": db_row["item_id"]}
-                        new_values = {"artists": f'[{ db_row["artist"]}]'}
-                        await self.update(TABLE_ALBUMS, match, new_values, db=db)
-                    try:
-                        await db.execute(
-                            f"ALTER TABLE {TABLE_ALBUMS} DROP COLUMN artist;"
-                        )
-                    except Exception:  # pylint: disable=broad-except
-                        pass  # old sqlite version
-
             # store current schema version
             await self.set_setting("version", str(SCHEMA_VERSION), db=db)