1515from macrostrat .core import app
1616from macrostrat .database import Database
1717from macrostrat .map_integration .commands .prepare_fields import _prepare_fields
18-
19- # from macrostrat.map_integration.pipeline import ingest_map
18+ #from macrostrat.map_integration.pipeline import ingest_map
2019from macrostrat .map_integration .process .geometry import create_rgeom , create_webgeom
2120from macrostrat .map_integration .utils .ingestion_utils import (
2221 find_gis_files ,
@@ -139,54 +138,14 @@ def delete_sources(
139138 dict (table = Identifier ("sources" , table )),
140139 )
141140
142- ingest_process = db .run_query (
143- """
144- SELECT id FROM maps_metadata.ingest_process
145- JOIN maps.sources ON maps.sources.source_id = maps_metadata.ingest_process.source_id
146- WHERE maps.sources.slug = :slug
147- """ ,
148- dict (slug = slug ),
149- ).fetchone ()
150-
151- if ingest_process :
152- ingest_process_id = ingest_process [0 ]
153-
154- print ("Ingest Process ID" , ingest_process_id )
155- if file_name is None :
156- rows = db .run_query (
157- "select f.object_id from maps_metadata.map_files f where ingest_process_id = :ingest_process_id" ,
158- dict (ingest_process_id = ingest_process_id ),
159- ).fetchall ()
160- object_ids = [r [0 ] for r in rows ]
161- db .run_sql (
162- "DELETE FROM maps_metadata.map_files WHERE ingest_process_id = :ingest_process_id" ,
163- dict (ingest_process_id = ingest_process_id ),
164- )
165- if object_ids :
166- db .run_sql (
167- """
168- DELETE FROM storage.object
169- WHERE id = ANY(:object_ids)
170- """ ,
171- dict (object_ids = object_ids ),
172- )
173-
174- db .run_sql (
175- "DELETE FROM maps_metadata.ingest_process_tag WHERE ingest_process_id = :ingest_process_id" ,
176- dict (ingest_process_id = ingest_process_id ),
177- )
178- db .run_sql (
179- "DELETE FROM maps_metadata.ingest_process WHERE id = :ingest_process_id" ,
180- dict (ingest_process_id = ingest_process_id ),
181- )
182-
183141 staging_delete_dir (s , db )
184142
185143 source_id = db .run_query (
186144 "SELECT source_id FROM maps.sources WHERE slug = :slug" ,
187145 dict (slug = s ),
188146 ).scalar ()
189147
148+
190149 # Delete ALL ingest-related rows for this source
191150 db .run_sql (
192151 """
@@ -308,6 +267,7 @@ def _run_migrations(database: str = None):
308267def staging (
309268 data_path : str ,
310269 prefix : str = Option (..., help = "Slug region prefix to avoid collisions" ),
270+ pipeline : str = Option ("" , help = "Specify a pipeline to run" ),
311271 merge_key : str = Option (
312272 "mapunit" ,
313273 help = "primary key to left join the metadata into the sources polygons/lines/points table" ,
@@ -343,6 +303,7 @@ def staging(
343303 ingest_results = ingest_map (
344304 slug ,
345305 gis_files ,
306+ pipeline = pipeline ,
346307 if_exists = "replace" ,
347308 meta_path = data_path ,
348309 merge_key = merge_key ,
@@ -434,28 +395,6 @@ def staging(
434395 create_rgeom (map_info )
435396 create_webgeom (map_info )
436397
437- # Ingest process assertions
438- if len (object_ids ) > 0 :
439- ingest_id = db .run_query (
440- """
441- SELECT id
442- FROM maps_metadata.ingest_process
443- WHERE source_id = :source_id
444- ORDER BY id DESC
445- LIMIT 1
446- """ ,
447- dict (source_id = source_id ),
448- ).scalar ()
449-
450- for object in object_ids :
451- db .run_sql (
452- """
453- INSERT INTO maps_metadata.map_files (ingest_process_id, object_id)
454- VALUES (:ingest_process_id, :object_id)
455- """ ,
456- dict (ingest_process_id = ingest_id , object_id = object ),
457- )
458-
459398 console .print (
460399 f"[green] \n Finished staging setup for { slug } . "
461400 f"View map here: https://dev.macrostrat.org/maps/ingestion/{ source_id } / [/green] \n "
@@ -470,12 +409,7 @@ def staging(
470409
471410
472411@staging_cli .command ("s3-upload" )
473- def cmd_upload_dir (
474- slug : str = ...,
475- data_path : Path = ...,
476- ext : str = Option (".gdb" , help = "extension of the data path" ),
477- ingest_process_id : int = Option (None ),
478- ):
412+ def cmd_upload_dir (slug : str = ..., data_path : Path = ..., ext : str = Option (".gdb" , help = "extension of the data path" ), ingest_process_id : int = Option (None )):
479413 """Upload a local directory to the staging bucket under SLUG/."""
480414 db = get_database ()
481415 source_id = db .run_query (
@@ -591,7 +525,6 @@ def list_layers(e00_path: Path) -> set[str]:
591525 def run (cmd ):
592526 p = subprocess .run (cmd , capture_output = True , text = True )
593527 return p .returncode , p .stdout , p .stderr
594-
595528 created = False
596529 for f in e00_files :
597530 base = f .stem
@@ -609,13 +542,9 @@ def run(cmd):
609542 # create/overwrite first successful write
610543 cmd += ["-overwrite" ]
611544 cmd += [
612- str (out_gpkg ),
613- str (f ),
614- lyr ,
615- "-nln" ,
616- f"{ base } _lines" ,
617- "-nlt" ,
618- "LINESTRING" ,
545+ str (out_gpkg ), str (f ), lyr ,
546+ "-nln" , f"{ base } _lines" ,
547+ "-nlt" , "LINESTRING" ,
619548 ]
620549 rc , _ , err = run (cmd )
621550 if rc == 0 :
@@ -628,13 +557,9 @@ def run(cmd):
628557 else :
629558 cmd = ["ogr2ogr" , "-f" , "GPKG" , "-update" , "-append" ]
630559 cmd += [
631- str (out_gpkg ),
632- str (f ),
633- lyr ,
634- "-nln" ,
635- f"{ base } _points" ,
636- "-nlt" ,
637- "POINT" ,
560+ str (out_gpkg ), str (f ), lyr ,
561+ "-nln" , f"{ base } _points" ,
562+ "-nlt" , "POINT" ,
638563 ]
639564 rc , _ , _ = run (cmd )
640565 if rc == 0 :
@@ -647,13 +572,9 @@ def run(cmd):
647572 else :
648573 cmd = ["ogr2ogr" , "-f" , "GPKG" , "-update" , "-append" ]
649574 cmd += [
650- str (out_gpkg ),
651- str (f ),
652- lyr ,
653- "-nln" ,
654- f"{ base } _polygons" ,
655- "-nlt" ,
656- "POLYGON" ,
575+ str (out_gpkg ), str (f ), lyr ,
576+ "-nln" , f"{ base } _polygons" ,
577+ "-nlt" , "POLYGON" ,
657578 ]
658579 rc , _ , _ = run (cmd )
659580 if rc == 0 :
@@ -663,7 +584,6 @@ def run(cmd):
663584
664585 print (f"Done: { out_gpkg } " )
665586
666-
667587# ----------------------------------------------------------------------------------------------------------------------
668588
669589
@@ -795,38 +715,19 @@ def staging_bulk(
795715 ),
796716 )
797717
718+
798719 cmd_upload_dir (slug = slug , data_path = region_path , ext = ext )
799720
721+
800722 map_info = get_map_info (db , slug )
801723 _prepare_fields (map_info )
802724 create_rgeom (map_info )
803725 create_webgeom (map_info )
804- # Ingest process assertions
805- if len (object_ids ) > 0 :
806- ingest_id = db .run_query (
807- """
808- SELECT id
809- FROM maps_metadata.ingest_process
810- WHERE source_id = :source_id
811- ORDER BY id DESC
812- LIMIT 1
813- """ ,
814- dict (source_id = source_id ),
815- ).scalar ()
816-
817- for object in object_ids :
818- db .run_sql (
819- """
820- INSERT INTO maps_metadata.map_files (ingest_process_id, object_id)
821- VALUES (:ingest_process_id, :object_id)
822- """ ,
823- dict (ingest_process_id = ingest_id , object_id = object ),
824- )
825726
826727 print (
827728 f"\n Finished staging setup for { slug } . View map here: https://dev.macrostrat.org/maps/ingestion/{ source_id } / \n "
828729 )
829730 slug_list_path = parent / f"staged_slugs.txt"
830731 with open (slug_list_path , "w" ) as file :
831732 for slug in staged_slugs :
832- file .write (slug + "\n " )
733+ file .write (slug + "\n " )
0 commit comments