@@ -66,7 +66,6 @@ def setup_new_inst(self, inst_name: str) -> None:
6666 )
6767 db_inst_name = databricksify_inst_name (inst_name )
6868 cat_name = databricks_vars ["CATALOG_NAME" ]
69- print (cat_name )
7069 for medallion in medallion_levels :
7170 w .schemas .create (name = f"{ db_inst_name } _{ medallion } " , catalog_name = cat_name )
7271 # Create a managed volume in the bronze schema for internal pipeline data.
@@ -143,3 +142,40 @@ def run_pdp_inference(
143142 },
144143 )
145144 return DatabricksInferenceRunResponse (job_run_id = run_job .response .run_id )
145+
146+ def delete_inst (self , inst_name : str ) -> None :
147+ db_inst_name = databricksify_inst_name (inst_name )
148+ cat_name = databricks_vars ["CATALOG_NAME" ]
149+ w = WorkspaceClient (
150+ host = databricks_vars ["DATABRICKS_HOST_URL" ],
151+ # This should still be cloud run, since it's cloud run triggering the databricks
152+ # this account needs to exist on Databricks as well and needs to have permissions.
153+ google_service_account = gcs_vars ["GCP_SERVICE_ACCOUNT_EMAIL" ],
154+ )
155+ # Delete the managed volume.
156+ w .volumes .delete (name = f"{ cat_name } .{ db_inst_name } _bronze.bronze_volume" )
157+ w .volumes .delete (name = f"{ cat_name } .{ db_inst_name } _silver.silver_volume" )
158+ w .volumes .delete (name = f"{ cat_name } .{ db_inst_name } _gold.gold_volume" )
159+
160+ # Delete the MLflow model.
161+ # TODO how to handle deleting all models?
162+ """
163+ model_name = "latest_enrollment_model"
164+ new_institution_model_uri = f"{cat_name}.{db_inst_name}_gold.{model_name}"
165+ mlflow_client.delete_registered_model(name=new_institution_model_uri)
166+ """
167+
168+ # Delete tables and schemas for each medallion level.
169+ for medallion in medallion_levels :
170+ all_tables = [
171+ table .name
172+ for table in w .tables .list (
173+ catalog_name = cat_name ,
174+ schema_name = f"{ db_inst_name } _{ medallion } " ,
175+ )
176+ ]
177+ for table in all_tables :
178+ w .tables .delete (
179+ full_name = f"{ cat_name } .{ db_inst_name } _{ medallion } .{ table } "
180+ )
181+ w .schemas .delete (full_name = f"{ cat_name } .{ db_inst_name } _{ medallion } " )
0 commit comments