From 719536b435f58237a69d68d35318c17fc2f17544 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 7 May 2022 21:38:12 +0200 Subject: [PATCH] Fix TypeError in initial database setup (#286) --- music_assistant/helpers/database.py | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/music_assistant/helpers/database.py b/music_assistant/helpers/database.py index 6bf0e770..b0fbac7e 100755 --- a/music_assistant/helpers/database.py +++ b/music_assistant/helpers/database.py @@ -150,24 +150,11 @@ class Database: sql_query += " WHERE " + " AND ".join((f"{x} = :{x}" for x in match)) await _db.execute(sql_query, match) - async def exists(self, table: str, db: Optional[Db] = None) -> bool: - """Return bool if table exists.""" - async with self.get_db(db) as _db: - try: - await _db.execute(f"SELECT COUNT(*) FROM '{table}'") - return True - except Exception as exc: # pylint: disable=broad-except - if table in str(exc): - return False - raise exc - async def _migrate(self): """Perform database migration actions if needed.""" async with self.get_db() as db: - if await self.exists(TABLE_SETTINGS, db): - prev_version = await self.get_setting("version", db) - prev_version = int(prev_version["value"]) - else: + prev_version = await self.get_setting("version", db) + if prev_version is None: prev_version = 0 if SCHEMA_VERSION != prev_version: @@ -177,7 +164,7 @@ class Database: SCHEMA_VERSION, ) - if prev_version < 3: + if prev_version < 4: # schema version 3: too many breaking changes, rebuild db await db.execute(f"DROP TABLE IF EXISTS {TABLE_ARTISTS}") await db.execute(f"DROP TABLE IF EXISTS {TABLE_ALBUMS}") @@ -187,14 +174,6 @@ class Database: await db.execute(f"DROP TABLE IF EXISTS {TABLE_PROV_MAPPINGS}") await db.execute(f"DROP TABLE IF EXISTS {TABLE_CACHE}") - if prev_version < 4: - # schema version 4: add album to tracks table - await db.execute("DROP TABLE IF EXISTS tracks") - if await self.exists(TABLE_PROV_MAPPINGS, db): - await self.delete( - TABLE_PROV_MAPPINGS, {"media_type": "track"}, db=db - ) - if prev_version < 5: # delete player_settings table: use generic settings table instead await db.execute("DROP TABLE IF EXISTS queue_settings") -- 2.34.1