Skip to content

Commit

Permalink
WIP Adds dry run option and contxtuals detection
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela committed Nov 17, 2023
1 parent c1d9cf9 commit ddf281e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions data/h3_data_importer/delete_h3_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from utils import get_connection_info

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


@click.command()
def main():
@click.option("--dry-run", is_flag=True)
def main(dry_run: bool):
with psycopg.connect(get_connection_info()) as conn:
with conn.cursor() as cursor:
# find all the tables that start with h3_grid*
Expand All @@ -24,14 +26,22 @@ def main():
tables_to_drop = cursor.fetchall()
if tables_to_drop:
for table in tables_to_drop:
cursor.execute(f"DROP TABLE {table[0]}")
log.info(
f"Tables {[table[0] for table in tables_to_drop]} don't have "
f"a corresponding entry in h3_data and were deleted"
if not dry_run:
cursor.execute(f"DROP TABLE {table[0]}")
log.info(f"Tables {[table[0] for table in tables_to_drop]} were deleted")
cursor.execute(
"""
SELECT "contextualLayerId" FROM h3_data
WHERE "h3tableName" in (%s)
""",
(tables_to_drop,),
)
tables_deleted_with_contextuals = cursor.fetchall()
print(tables_deleted_with_contextuals)
else:
log.info("No tables to delete")


if __name__ == "__main__":
log.info("Starting delete_h3_tables.py")
main()

0 comments on commit ddf281e

Please sign in to comment.