From 24fa76ee30860877057d68f2b6bf7064859ab4b5 Mon Sep 17 00:00:00 2001 From: python357-1 <30739625+python357-1@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:03:11 -0600 Subject: [PATCH] tests(fix): stop updating sqlite db during tests (#648) * fix: stop sqlite db from being updated while running tests * refactor: small refactor in db checking code --- tagstudio/src/core/library/alchemy/db.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tagstudio/src/core/library/alchemy/db.py b/tagstudio/src/core/library/alchemy/db.py index f1a23f5d3..2152d4244 100644 --- a/tagstudio/src/core/library/alchemy/db.py +++ b/tagstudio/src/core/library/alchemy/db.py @@ -37,10 +37,14 @@ def make_tables(engine: Engine) -> None: # tag IDs < 1000 are reserved # create tag and delete it to bump the autoincrement sequence # TODO - find a better way + # is this the better way? with engine.connect() as conn: - conn.execute(text("INSERT INTO tags (id, name, color) VALUES (999, 'temp', 1)")) - conn.execute(text("DELETE FROM tags WHERE id = 999")) - conn.commit() + result = conn.execute(text("SELECT SEQ FROM sqlite_sequence WHERE name='tags'")) + autoincrement_val = result.scalar() + if not autoincrement_val or autoincrement_val < 1000: + conn.execute(text("INSERT INTO tags (id, name, color) VALUES (999, 'temp', 1)")) + conn.execute(text("DELETE FROM tags WHERE id = 999")) + conn.commit() def drop_tables(engine: Engine) -> None: