diff --git a/src/tagstudio/core/library/alchemy/library.py b/src/tagstudio/core/library/alchemy/library.py index df4c5e8e..3684b606 100644 --- a/src/tagstudio/core/library/alchemy/library.py +++ b/src/tagstudio/core/library/alchemy/library.py @@ -584,7 +584,7 @@ class Library: if loaded_db_version < v and (iv is None or initial_db_version < iv): with session: # any error causes transaction to rollback - migration(session) + migration(session, library_dir) loaded_db_version = v self.set_version(session, DB_VERSION_CURRENT_KEY, v) session.commit() @@ -610,7 +610,7 @@ class Library: self.library_dir = library_dir return LibraryStatus(success=True, library_path=library_dir) - def __apply_db7_migration(self, session: Session): + def __apply_db7_migration(self, session: Session, library_dir: Path): """Migrate DB from DB_VERSION 6 to 7.""" logger.info("[Library][Migration][7] Applying patches to DB_VERSION: 6 library...") # Repair tags that may have a disambiguation_id pointing towards a deleted tag. @@ -623,7 +623,7 @@ class Library: session.execute(disam_stmt) session.flush() - def __apply_db8_migration(self, session: Session): + def __apply_db8_migration(self, session: Session, library_dir: Path): """Migrate DB from DB_VERSION 7 to 8.""" # Add the missing color_border column to the TagColorGroups table. session.execute( @@ -671,7 +671,7 @@ class Library: session.execute(neon_stmt) session.flush() - def __apply_db9_migration(self, session: Session): + def __apply_db9_migration(self, session: Session, library_dir: Path): """Migrate DB from DB_VERSION 8 to 9.""" # Apply database schema changes add_filename_column = text( @@ -687,7 +687,7 @@ class Library: session.flush() logger.info("[Library][Migration][9] Populated filename column in entries table") - def __apply_db100_migration(self, session: Session): + def __apply_db100_migration(self, session: Session, library_dir: Path): """Migrate DB to DB_VERSION 100.""" # Repair parent-child tag relationships that are the wrong way around. stmt = update(TagParent).values( @@ -698,20 +698,20 @@ class Library: session.flush() logger.info("[Library][Migration][100] Refactored TagParent table") - def __apply_db101_migration(self, session: Session): + def __apply_db101_migration(self, session: Session, library_dir: Path): """Migrate DB to DB_VERSION 101.""" # Ensure version rows are present session.add(Version(key=DB_VERSION_INITIAL_KEY, value=100)) session.flush() - def __apply_db102_migration(self, session: Session): + def __apply_db102_migration(self, session: Session, library_dir: Path): """Migrate DB to DB_VERSION 102.""" stmt = delete(TagParent).where(TagParent.parent_id.not_in(select(Tag.id).distinct())) session.execute(stmt) session.flush() logger.info("[Library][Migration][102] Verified TagParent table data") - def __apply_db103_migration(self, session: Session): + def __apply_db103_migration(self, session: Session, library_dir: Path): """Migrate DB from DB_VERSION 102 to 103.""" # add the new hidden column for tags session.execute(text("ALTER TABLE tags ADD COLUMN is_hidden BOOLEAN NOT NULL DEFAULT 0")) @@ -747,7 +747,7 @@ class Library: with open(ts_ignore, "w") as f: f.write(migrate_ext_list(extensions, is_exclude_list)) - def __apply_db200_migration(self, session: Session): + def __apply_db200_migration(self, session: Session, library_dir: Path): """Migrate DB to DB_VERSION 200.""" # Drop unused 'boolean_fields' and 'value_type' tables logger.info("[Library][Migration][200] Dropping boolean_fields and value_type tables...") @@ -834,7 +834,7 @@ class Library: text("CREATE INDEX IF NOT EXISTS idx_tag_entries_entry_id ON tag_entries (entry_id)") ) - def __apply_db201_migration(self, session: Session): + def __apply_db201_migration(self, session: Session, library_dir: Path): """Migrate DB to DB_VERSION 201.""" create_text_fields_table = text(""" CREATE TABLE text_fields_new ( @@ -884,7 +884,7 @@ class Library: session.flush() - def __apply_db202_migration(self, session: Session): + def __apply_db202_migration(self, session: Session, library_dir: Path): """Migrate DB to DB_VERSION 202.""" stmt = delete(TagParent).where(TagParent.child_id.not_in(select(Tag.id).distinct())) session.execute(stmt) diff --git a/src/tagstudio/qt/mixed/migration_modal.py b/src/tagstudio/qt/mixed/migration_modal.py index 93e983a1..79a26c26 100644 --- a/src/tagstudio/qt/mixed/migration_modal.py +++ b/src/tagstudio/qt/mixed/migration_modal.py @@ -401,6 +401,8 @@ class JsonMigrationModal(QObject): 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) )