From db520890a2f91c60c09f6993a47180652593d64e Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Mon, 6 Jul 2026 14:17:31 +0200 Subject: [PATCH] refactor: add assurance 1 version check Assurance 1 was introduced with library version 101, specifically commmit 12e074b71d8860282b44e49e0e1a41b7a2e4bae8. Thus all libraries created on version 101 and above already fullfill it and don't need it. Furthermore, it only fails if the library didn't need the assurance, meaning the try-except and warning catching can be removed --- src/tagstudio/core/library/alchemy/library.py | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/tagstudio/core/library/alchemy/library.py b/src/tagstudio/core/library/alchemy/library.py index b8018871..731d4f2f 100644 --- a/src/tagstudio/core/library/alchemy/library.py +++ b/src/tagstudio/core/library/alchemy/library.py @@ -538,7 +538,6 @@ class Library: return LibraryStatus(success=True, library_path=library_dir) def migrate_lib(self, library_dir: Path, storage_path: str) -> LibraryStatus: - is_new = False connection_string = URL.create( drivername="sqlite", database=storage_path, @@ -591,24 +590,18 @@ class Library: # without considering what version the DB is currently on and then doing all of the # migrations after that seems like it could cause problems in some scenarios. # instead only have this on creation and create new tables as part of migrations + # Note: this actually produces an error and fails to initialise built-in tags when opening + # a library that doesn't yet have the is_hidden property on the tags table make_tables(self.engine) with Session(self.engine) as session: - # TODO ASSURANCE 1: version check + reordering + # TODO ASSURANCE 1: reordering # Ensure version rows are present - with catch_warnings(record=True): - try: - initial = DB_VERSION if is_new else 100 - session.add(Version(key=DB_VERSION_INITIAL_KEY, value=initial)) - session.commit() - except IntegrityError: - session.rollback() + if loaded_db_version < 101: + session.add(Version(key=DB_VERSION_INITIAL_KEY, value=100)) - try: - session.add(Version(key=DB_VERSION_CURRENT_KEY, value=DB_VERSION)) - session.commit() - except IntegrityError: - session.rollback() + session.add(Version(key=DB_VERSION_CURRENT_KEY, value=DB_VERSION)) + session.commit() # TODO ASSURANCE 2: version check + reordering # check if folder matching current path exists already