From 3f1ae30dd538fd6181c8864bfb0e05c9ea971996 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Mon, 27 Mar 2023 06:44:11 +0300 Subject: [PATCH] add migration to drop album and artist tables --- app/lib/searchlib.py | 2 -- app/migrations/__preinit/__init__.py | 5 +++- .../drop_artist_and_album_color_tables.py | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 app/migrations/__preinit/drop_artist_and_album_color_tables.py diff --git a/app/lib/searchlib.py b/app/lib/searchlib.py index b69806f5..e2374cac 100644 --- a/app/lib/searchlib.py +++ b/app/lib/searchlib.py @@ -197,8 +197,6 @@ class SearchAll: itertools.groupby(mapped_items, lambda x: x["type"]) ] - print(len(groups)) - # merge items of a group into a dict that looks like: {"albums": [album1, ...]} groups = [ {f"{group[0]['type']}s": [i['item'] for i in group]} for group in groups diff --git a/app/migrations/__preinit/__init__.py b/app/migrations/__preinit/__init__.py index c834a375..e748779f 100644 --- a/app/migrations/__preinit/__init__.py +++ b/app/migrations/__preinit/__init__.py @@ -2,6 +2,8 @@ Pre-init migrations are executed before the database is created. Useful when you need to move files or folders before the database is created. +`Example use cases: Moving files around, dropping tables, etc.` + PLEASE NOTE: OLDER MIGRATIONS CAN NEVER BE DELETED. ONLY MODIFY OLD MIGRATIONS FOR BUG FIXES OR ENHANCEMENTS ONLY. [TRY NOT TO MODIFY BEHAVIOR, UNLESS YOU KNOW WHAT YOU'RE DOING]. @@ -11,9 +13,10 @@ from sqlite3 import OperationalError from app.db.sqlite.migrations import MigrationManager from app.logger import log +from .drop_artist_and_album_color_tables import DropArtistAndAlbumColorTables from .move_to_xdg_folder import MoveToXdgFolder -all_preinits = [MoveToXdgFolder] +all_preinits = [MoveToXdgFolder, DropArtistAndAlbumColorTables] def run_preinit_migrations(): diff --git a/app/migrations/__preinit/drop_artist_and_album_color_tables.py b/app/migrations/__preinit/drop_artist_and_album_color_tables.py new file mode 100644 index 00000000..816ee24f --- /dev/null +++ b/app/migrations/__preinit/drop_artist_and_album_color_tables.py @@ -0,0 +1,24 @@ +""" +Another shot at attempting to fix duplicate album and artist color entries. +This release should finally fix the issue. The migration script will now remove +the album and artist color tables and recreate them. +""" + +from app.db.sqlite.utils import SQLiteManager +from app.logger import log + + +class DropArtistAndAlbumColorTables: + version = 2 + name = "DropArtistAndAlbumColorTables" + + @staticmethod + def migrate(): + with SQLiteManager() as cur: + tables = ["artists", "albums"] + for table in tables: + cur.execute(f"DROP TABLE IF EXISTS {table}") + + cur.execute("VACUUM") + + log.info("Deleted artist and album color data to fix a few bugs. ✅")