Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlink dangling contextuals during ingestion #1200

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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__/
2 changes: 1 addition & 1 deletion data/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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... "
Expand Down
2 changes: 1 addition & 1 deletion data/h3_data_importer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,4 @@ clean:
rm -rf data/*

delete-h3-tables:
python delete_h3_tables.py
python delete_h3_tables.py --drop-contextuals
5 changes: 4 additions & 1 deletion data/h3_data_importer/delete_h3_tables.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Dangling layer deleter/unlinker"""

import logging

import click
Expand All @@ -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*
Expand Down Expand Up @@ -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:
Expand Down