From 6e64dc442751ada3cda9ef0c6933040869c5ee3f Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Mon, 6 Jul 2026 19:05:48 +0200 Subject: [PATCH] fix: json migration used outdated interface --- src/tagstudio/core/library/alchemy/library.py | 28 +++++++++---------- src/tagstudio/qt/mixed/migration_modal.py | 13 ++++----- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/tagstudio/core/library/alchemy/library.py b/src/tagstudio/core/library/alchemy/library.py index 5513c26b..32d22b67 100644 --- a/src/tagstudio/core/library/alchemy/library.py +++ b/src/tagstudio/core/library/alchemy/library.py @@ -380,7 +380,7 @@ class Library: return tag.name def open_library(self, library_dir: Path, in_memory: bool = False) -> LibraryStatus: - """Wrapper for open_sqlite_library. + """Wrapper for open_sqlite_library and create_sqlite_library. Handles in-memory storage and checks whether a JSON-migration is necessary. """ @@ -399,21 +399,17 @@ class Library: json_migration_req=True, ) - return self.open_sqlite_library(library_dir, is_new, in_memory) - - def open_sqlite_library( - self, library_dir: Path, is_new: bool, in_memory: bool - ) -> LibraryStatus: if is_new: - return self.new_lib(library_dir, in_memory) - return self.migrate_lib(library_dir, in_memory) + return self.create_sqlite_library(library_dir, in_memory) + + return self.open_sqlite_library(library_dir, in_memory) @staticmethod - def __get_engine(library_dir: Path, in_memory: bool): + def __get_engine(library_dir: Path, in_memory: bool, sql_filename: str): connection_string = URL.create( drivername="sqlite", database=( - ":memory:" if in_memory else str(library_dir / TS_FOLDER_NAME / SQL_FILENAME) + ":memory:" if in_memory else str(library_dir / TS_FOLDER_NAME / sql_filename) ), ) # NOTE: File-based databases should use NullPool to create new DB connection in order to @@ -432,8 +428,10 @@ class Library: ) return create_engine(connection_string, poolclass=poolclass) - def new_lib(self, library_dir: Path, in_memory: bool) -> LibraryStatus: - self.engine = self.__get_engine(library_dir, in_memory) + def create_sqlite_library( + self, library_dir: Path, in_memory: bool, sql_filename: str = SQL_FILENAME + ) -> LibraryStatus: + self.engine = self.__get_engine(library_dir, in_memory, sql_filename) loaded_db_version: int = 0 logger.info( @@ -514,8 +512,10 @@ class Library: self.library_dir = library_dir return LibraryStatus(success=True, library_path=library_dir) - def migrate_lib(self, library_dir: Path, in_memory: bool) -> LibraryStatus: - self.engine = self.__get_engine(library_dir, in_memory) + def open_sqlite_library( + self, library_dir: Path, in_memory: bool, sql_filename: str = SQL_FILENAME + ) -> LibraryStatus: + self.engine = self.__get_engine(library_dir, in_memory, sql_filename) loaded_db_version: int = 0 initial_db_version: int = DB_VERSION diff --git a/src/tagstudio/qt/mixed/migration_modal.py b/src/tagstudio/qt/mixed/migration_modal.py index 79a26c26..77850a72 100644 --- a/src/tagstudio/qt/mixed/migration_modal.py +++ b/src/tagstudio/qt/mixed/migration_modal.py @@ -395,16 +395,15 @@ class JsonMigrationModal(QObject): # Convert JSON Library to SQLite yield Translations["json_migration.creating_database_tables"] self.sql_lib = SqliteLibrary() - self.temp_path: Path = ( - self.json_lib.library_dir / TS_FOLDER_NAME / "migration_ts_library.sqlite" - ) + temp_filename = "migration_ts_library.sqlite" + self.temp_path: Path = self.json_lib.library_dir / TS_FOLDER_NAME / temp_filename if self.temp_path.exists(): logger.info('Temporary migration file "temp_path" already exists. Removing...') self.temp_path.unlink() - # TODO: fix syntax error - # Is the usage of the temporary directory really necessary here? - self.sql_lib.open_sqlite_library( - self.json_lib.library_dir, is_new=True, storage_path=str(self.temp_path) + self.sql_lib.create_sqlite_library( + self.json_lib.library_dir, + in_memory=False, + sql_filename=temp_filename, ) yield Translations.format( "json_migration.migrating_files_entries", entries=len(self.json_lib.entries)