refactor: move set_version to DBMigrations

This commit is contained in:
Jann Stute
2026-07-24 16:13:36 +02:00
parent ccd07ee0ff
commit 92b40a72a9
2 changed files with 12 additions and 14 deletions
@@ -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()
@@ -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