Skip to content

Commit

Permalink
Add removing of views and combine implementation with removing triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
margrietpalm committed Dec 12, 2024
1 parent bc199c9 commit 28d222d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions threedi_schema/migrations/versions/0229_clean_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ def clean_geometry_columns():
"""))


def clean_triggers():
""" Remove triggers referencing v2 tables """
def clean_by_type(type: str):
connection = op.get_bind()
triggers = [item[0] for item in connection.execute(
sa.text("SELECT tbl_name FROM sqlite_master WHERE type='trigger' AND tbl_name LIKE '%v2%';")).fetchall()]
for trigger in triggers:
op.execute(f"DROP TRIGGER IF EXISTS {trigger};")
items = [item[0] for item in connection.execute(
sa.text(f"SELECT tbl_name FROM sqlite_master WHERE type='{type}' AND tbl_name LIKE '%v2%';")).fetchall()]
for item in items:
op.execute(f"DROP {type} IF EXISTS {item};")


def update_use_settings():
Expand Down Expand Up @@ -131,7 +130,8 @@ def update_use_settings():
def upgrade():
remove_old_tables()
clean_geometry_columns()
clean_triggers()
clean_by_type('triggers')
clean_by_type('views')
update_use_settings()
# Apply changing use_2d_rain and friction_averaging type to bool
sync_orm_types_to_sqlite('model_settings')
Expand Down

0 comments on commit 28d222d

Please sign in to comment.