From 4496754f49ef37be54833beb03e2ce74542c032d Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Thu, 3 Sep 2026 20:14:04 +0200 Subject: [PATCH] refactor: sqlalchemy-independence for the DB 102 migration --- src/tagstudio/core/library/alchemy/migrations.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tagstudio/core/library/alchemy/migrations.py b/src/tagstudio/core/library/alchemy/migrations.py index b7f96a5e..3c977d55 100644 --- a/src/tagstudio/core/library/alchemy/migrations.py +++ b/src/tagstudio/core/library/alchemy/migrations.py @@ -297,12 +297,16 @@ class MigrationTo102(DBMigration): @override @classmethod - def run(cls, session: Session, library_dir: Path, fmt_log: LoggingMethod): + def run(cls, conn: Connection, library_dir: Path, fmt_log: LoggingMethod): """Migrate DB to DB_VERSION 102.""" # delete TagParents with a dangling parent reference - stmt = delete(TagParent).where(TagParent.parent_id.not_in(select(Tag.id).distinct())) - session.execute(stmt) - session.flush() + conn.execute(""" + DELETE FROM tag_parents + WHERE NOT parent_id IN ( + SELECT id + FROM tags + ) + """) logger.info(fmt_log("Verified TagParent table data"))