From 99ec11565c54ec69a9322b68707c73e7f87eeee6 Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Mon, 11 Mar 2024 11:33:59 +0300 Subject: [PATCH] fix migrations deleting all playlists --- .TODO.md | 13 +++++++++++++ app/api/playlist.py | 3 +-- app/api/search.py | 3 +-- app/migrations/__init__.py | 9 +++------ 4 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .TODO.md diff --git a/.TODO.md b/.TODO.md new file mode 100644 index 00000000..d508ea0d --- /dev/null +++ b/.TODO.md @@ -0,0 +1,13 @@ +# TODO +A list of things to do. Feel free to grab one of this and work on it. + +## Clean up old playlist images +When playlists are deleted or their images updated, the old +images are not deleted. + +Write a function to: +- read all images in the playlist image directory and checks unlinked images by comparing the list with the .image property of each property +- delete unlinked images + +The function can run on app start up, before periodic checks + diff --git a/app/api/playlist.py b/app/api/playlist.py index 0247901b..91461fdf 100644 --- a/app/api/playlist.py +++ b/app/api/playlist.py @@ -26,12 +26,11 @@ api = APIBlueprint("playlists", __name__, url_prefix="/playlists", abp_tags=[tag PL = SQLitePlaylistMethods - class SendAllPlaylistsQuery(BaseModel): no_images: bool = Field(False, description="Whether to include images") -@api.get("", methods=["GET"]) +@api.get("") def send_all_playlists(query: SendAllPlaylistsQuery): """ Gets all the playlists. diff --git a/app/api/search.py b/app/api/search.py index cff4cee1..871c3dcf 100644 --- a/app/api/search.py +++ b/app/api/search.py @@ -138,9 +138,8 @@ def get_top_results(query: TopResultsQuery): Returns the top results for the given query. """ - - query = query.q limit = query.limit + query = query.q in_quotes = query_in_quotes(query) diff --git a/app/migrations/__init__.py b/app/migrations/__init__.py index 8aaf1f5e..c35baf71 100644 --- a/app/migrations/__init__.py +++ b/app/migrations/__init__.py @@ -10,7 +10,6 @@ ONLY MODIFY OLD MIGRATIONS FOR BUG FIXES OR ENHANCEMENTS ONLY PS: Fuck that! Do what you want. """ - from app.db.sqlite.migrations import MigrationManager from app.logger import log from app.migrations import v1_3_0, v1_4_9 @@ -27,9 +26,7 @@ migrations: list[list[Migration]] = [ v1_3_0.RemoveAllTracks, v1_3_0.UpdateAppSettingsTable, ], - [ - v1_4_9.AddTimestampToFavoritesTable - ] + [v1_4_9.AddTimestampToFavoritesTable], ] @@ -41,8 +38,8 @@ def apply_migrations(): version = MigrationManager.get_version() if version != len(migrations): - # run migrations after the previous migration version - for migration in migrations[(version - 1) :]: + # INFO: Apply new migrations + for migration in migrations[version:]: for m in migration: try: m.migrate()