Skip to content

Commit

Permalink
Added guards for non-existent tables
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed May 11, 2024
1 parent 51e3d6f commit 256b8eb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions map-integration/macrostrat/map_integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .migrations import run_migrations
from .pipeline import ingest_file, ingest_from_csv, ingest_object, run_polling_loop
from .process import cli as _process
from .utils import IngestionCLI, MapInfo
from .utils import IngestionCLI, MapInfo, table_exists

help_text = f"""Ingest maps into Macrostrat.
Expand Down Expand Up @@ -163,6 +163,10 @@ def change_slug(map: MapInfo, new_slug: str, dry_run: bool = False):
with db.transaction():
# Change sources table names
for table in ["polygons", "lines", "points"]:
# Check if the table exists
if not table_exists(db, f"{map.slug}_{table}", schema="sources"):
continue

if dry_run:
print(f"Would rename {map.slug}_{table} to {new_slug}_{table}")
continue
Expand All @@ -179,7 +183,7 @@ def change_slug(map: MapInfo, new_slug: str, dry_run: bool = False):
if dry_run:
return

db.run_sql(
db.run_query(
"UPDATE maps.sources SET slug = :new_slug WHERE source_id = :source_id",
dict(new_slug=new_slug, source_id=map.id),
)
Expand Down

0 comments on commit 256b8eb

Please sign in to comment.