Skip to content

Commit

Permalink
Merge pull request #51 from UW-Macrostrat/delete-source
Browse files Browse the repository at this point in the history
Update the 'sources delete' subcommand to handle ingest processes
  • Loading branch information
davenquinn authored May 10, 2024
2 parents fbd9bd8 + 1a9b267 commit b939d1f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion map-integration/macrostrat/map_integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ def set_active_map(map: MapInfo = None):
cli.add_command(apply_srid, name="apply-srid")

cli.add_command(ingest_file, name="ingest-file")
cli.add_command(ingest_from_csv, name="ingest-from-csv", context_settings={"allow_extra_args": True, "ignore_unknown_options": True})
cli.add_command(
ingest_from_csv,
name="ingest-from-csv",
context_settings={
"allow_extra_args": True,
"ignore_unknown_options": True,
},
)
cli.add_command(ingest_object, name="ingest-object")
cli.add_command(run_polling_loop, name="run-polling-loop")

Expand Down Expand Up @@ -104,6 +111,29 @@ def delete_sources(
dict(table=Identifier("sources", table)),
)

ingest_process = db.run_query(
"""
SELECT id FROM maps_metadata.ingest_process
JOIN maps.sources ON maps.sources.source_id = maps_metadata.ingest_process.source_id
WHERE maps.sources.slug = :slug
""",
dict(slug=slug),
).fetchone()

if ingest_process:
ingest_process_id = ingest_process[0]

print("Ingest Process ID", ingest_process_id)

db.run_sql(
"DELETE FROM maps_metadata.ingest_process_tag WHERE ingest_process_id = :ingest_process_id",
dict(ingest_process_id=ingest_process_id),
)
db.run_sql(
"DELETE FROM maps_metadata.ingest_process WHERE id = :ingest_process_id",
dict(ingest_process_id=ingest_process_id),
)

db.run_sql("DELETE FROM maps.sources WHERE slug = :slug", dict(slug=slug))


Expand Down

0 comments on commit b939d1f

Please sign in to comment.