Skip to content

Commit

Permalink
fix refresh view
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez committed Apr 11, 2024
1 parent b381177 commit a8e483e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion functions-python/batch_process_dataset/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def create_dataset(self, dataset_file: DatasetFile):
session.add(latest_dataset)
session.add(new_dataset)

refresh_materialized_view(t_feedsearch.name)
refresh_materialized_view(session, t_feedsearch.name)
session.commit()
logging.info(f"[{self.feed_stable_id}] Dataset created successfully.")
except Exception as e:
Expand Down
33 changes: 23 additions & 10 deletions functions-python/test_utils/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,30 @@ def get_testing_session() -> Session:


def clean_testing_db():
"""Truncates all table in the test db."""
"""Deletes all rows from all tables in the test db, excluding those in excluded_tables."""
engine = get_testing_engine()
with contextlib.closing(engine.connect()) as con:
trans = con.begin()
query = "TRUNCATE {} RESTART IDENTITY;".format(
",".join(
try:
tables_to_delete = [
table.name
for table in filter(
lambda t: t.name not in excluded_tables, Base.metadata.sorted_tables
)
)
)
con.execute(text(query))
trans.commit()
for table in reversed(Base.metadata.sorted_tables)
if table.name not in excluded_tables
]
# Disable triggers for each table
for table_name in tables_to_delete:
con.execute(text(f"ALTER TABLE {table_name} DISABLE TRIGGER ALL;"))

# Delete all rows from each table
for table_name in tables_to_delete:
delete_query = f"DELETE FROM {table_name};"
con.execute(text(delete_query))

# Re-enable triggers for each table
for table_name in tables_to_delete:
con.execute(text(f"ALTER TABLE {table_name} ENABLE TRIGGER ALL;"))

trans.commit()
except Exception as error:
trans.rollback()
logging.error(f"Error while deleting from test db: {error}")

0 comments on commit a8e483e

Please sign in to comment.