From 92b40a72a9f31206578f8e0ab31031d899220ef8 Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Fri, 24 Jul 2026 16:13:36 +0200 Subject: [PATCH] refactor: move set_version to DBMigrations --- src/tagstudio/core/library/alchemy/library.py | 12 ------------ src/tagstudio/core/library/alchemy/migrations.py | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/tagstudio/core/library/alchemy/library.py b/src/tagstudio/core/library/alchemy/library.py index 49cf8014..d582a82f 100644 --- a/src/tagstudio/core/library/alchemy/library.py +++ b/src/tagstudio/core/library/alchemy/library.py @@ -1774,18 +1774,6 @@ class Library: except Exception: return 0 - @staticmethod - def _set_version(session: Session, key: str, value: int) -> None: - """Set a version value to the DB. - - Args: - session(Session): The SQLAlchemy DB Session to use. - key(str): The key for the name of the version type to set. - value(int): The version value to set. - """ - # Insert if key has no value yet, otherwise update the value - session.merge(Version(key=key, value=value)) - def mirror_entry_fields(self, entries: list[Entry]) -> None: """Mirror fields among multiple Entry items.""" all_fields: set[BaseField] = set() diff --git a/src/tagstudio/core/library/alchemy/migrations.py b/src/tagstudio/core/library/alchemy/migrations.py index 6685556d..2951f02d 100644 --- a/src/tagstudio/core/library/alchemy/migrations.py +++ b/src/tagstudio/core/library/alchemy/migrations.py @@ -80,7 +80,6 @@ class DBMigrations: return self.loaded_db_version < DB_VERSION def run(self): - from tagstudio.core.library.alchemy.library import Library # migrate DB step by step from one version to the next # (migration_method, db_version, initial_db_version) @@ -113,7 +112,7 @@ class DBMigrations: ) self.loaded_db_version = migration.version try: - Library._set_version(session, DB_VERSION_CURRENT_KEY, migration.version) + self.__set_version(session, DB_VERSION_CURRENT_KEY, migration.version) except Exception as e: logger.info( f"[Library][Migration][{migration.version}] " @@ -130,6 +129,17 @@ class DBMigrations: ) logger.info(f"[Library][Migration] Library migrated to DB version {DB_VERSION}") + def __set_version(self, session: Session, key: str, value: int) -> None: + """Set a version value to the DB. + + Args: + session(Session): The SQLAlchemy DB Session to use. + key(str): The key for the name of the version type to set. + value(int): The version value to set. + """ + # Insert if key has no value yet, otherwise update the value + session.merge(Version(key=key, value=value)) + class MigrationTo7(DBMigration): version = 7