From b509154ee8b6b5dd163ed030b45c49b5c1b26aa4 Mon Sep 17 00:00:00 2001 From: Biel Stela Date: Tue, 25 Jun 2024 09:50:15 +0200 Subject: [PATCH] Adds contextual deleters to general pipeline --- .gitignore | 4 ++++ data/Makefile | 2 +- data/h3_data_importer/Makefile | 2 +- data/h3_data_importer/delete_h3_tables.py | 5 ++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0f397983f..7ded7d506 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ infrastructure/kubernetes/vars/* !infrastructure/base/vars/terraform.tfvars !infrastructure/kubernetes/vars/terraform.tfvars /infrastructure/kubernetes/bastion_tunnel.sh + +# python land + +__pycache__/ diff --git a/data/Makefile b/data/Makefile index f5fc75d6d..58823a4d4 100644 --- a/data/Makefile +++ b/data/Makefile @@ -13,7 +13,7 @@ do-nothing: @echo "Doing nothing... " # ## Make Dataset -seed-data: seed-source-data seed-gadm seed-h3-tables seed-contextual-layers seed-indicator-coefficients +seed-data: seed-source-data seed-gadm seed-h3-tables seed-contextual-layers seed-indicator-coefficients delete-h3-tables seed-source-data: @echo "Importing source data... " diff --git a/data/h3_data_importer/Makefile b/data/h3_data_importer/Makefile index 8f835bbb8..d162a69d6 100644 --- a/data/h3_data_importer/Makefile +++ b/data/h3_data_importer/Makefile @@ -357,4 +357,4 @@ clean: rm -rf data/* delete-h3-tables: - python delete_h3_tables.py + python delete_h3_tables.py --drop-contextuals diff --git a/data/h3_data_importer/delete_h3_tables.py b/data/h3_data_importer/delete_h3_tables.py index c72f9adfb..e230914ea 100644 --- a/data/h3_data_importer/delete_h3_tables.py +++ b/data/h3_data_importer/delete_h3_tables.py @@ -1,3 +1,5 @@ +"""Dangling layer deleter/unlinker""" + import logging import click @@ -13,6 +15,7 @@ @click.option("--drop-contextuals", is_flag=True) @click.option("--dry-run", is_flag=True) def main(drop_contextuals: bool, dry_run: bool): + """Deletes unlinked and dangling layers from the DB""" with psycopg.connect(get_connection_info()) as conn: with conn.cursor() as cursor: # find all the tables that start with h3_grid* @@ -51,7 +54,7 @@ def main(drop_contextuals: bool, dry_run: bool): """DELETE FROM contextual_layer WHERE id = ANY(%s); """, - (list(ctx[0] for ctx in contextuals_to_drop),), + ([ctx[0] for ctx in contextuals_to_drop],), ) log.info(f"Deleted contextual layers {', '.join(str(ctx[0]) for ctx in contextuals_to_drop)}") else: