Skip to content

Commit bbe3b37

Browse files
committed
fix: use recommended renaming order for field tables
1 parent 3fc5f74 commit bbe3b37

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/tagstudio/core/library/alchemy/library.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def __apply_db201_migrations(self, session: Session):
869869
"""Migrate DB to DB_VERSION 201."""
870870
with session:
871871
create_text_fields_table = text("""
872-
CREATE TABLE text_fields (
872+
CREATE TABLE text_fields_new (
873873
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
874874
name VARCHAR NOT NULL,
875875
entry_id INTEGER NOT NULL,
@@ -879,7 +879,7 @@ def __apply_db201_migrations(self, session: Session):
879879
)
880880
""")
881881
create_datetime_fields_table = text("""
882-
CREATE TABLE datetime_fields (
882+
CREATE TABLE datetime_fields_new (
883883
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
884884
name VARCHAR NOT NULL,
885885
entry_id INTEGER NOT NULL,
@@ -889,32 +889,30 @@ def __apply_db201_migrations(self, session: Session):
889889
""")
890890

891891
logger.info("[Library][Migration][201] Dropping type_key from text_fields table...")
892-
session.execute(text("ALTER TABLE text_fields RENAME TO text_fields_old"))
893-
session.flush()
894892
session.execute(create_text_fields_table)
895893
session.flush()
896894
session.execute(
897895
text("""
898-
INSERT INTO text_fields (id, name, entry_id, value, is_multiline)
896+
INSERT INTO text_fields_new (id, name, entry_id, value, is_multiline)
899897
SELECT id, name, entry_id, value, is_multiline
900-
FROM text_fields_old
898+
FROM text_fields
901899
""")
902900
)
903-
session.execute(text("DROP TABLE text_fields_old"))
901+
session.execute(text("DROP TABLE text_fields"))
902+
session.execute(text("ALTER TABLE text_fields_new RENAME TO text_fields"))
904903

905904
logger.info("[Library][Migration][201] Dropping type_key from datetime_fields table...")
906-
session.execute(text("ALTER TABLE datetime_fields RENAME TO datetime_fields_old"))
907-
session.flush()
908905
session.execute(create_datetime_fields_table)
909906
session.flush()
910907
session.execute(
911908
text("""
912-
INSERT INTO datetime_fields (id, name, entry_id, value)
909+
INSERT INTO datetime_fields_new (id, name, entry_id, value)
913910
SELECT id, name, entry_id, value
914-
FROM datetime_fields_old
911+
FROM datetime_fields
915912
""")
916913
)
917-
session.execute(text("DROP TABLE datetime_fields_old"))
914+
session.execute(text("DROP TABLE datetime_fields"))
915+
session.execute(text("ALTER TABLE datetime_fields_new RENAME TO datetime_fields"))
918916

919917
session.commit()
920918

0 commit comments

Comments
 (0)