Skip to content

Commit

Permalink
Merge pull request #494 from DalgoT4D/adhoc-changes-ui4t
Browse files Browse the repository at this point in the history
Hide under construction things; delete apis
  • Loading branch information
fatchat authored Mar 5, 2024
2 parents 5b97ead + 053c301 commit 947a91e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 19 deletions.
110 changes: 91 additions & 19 deletions ddpui/api/transform_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,16 @@ def get_input_sources_and_models(request, schema_name: str = None):

res = []
for orgdbt_model in query.all():
res.append(
{
"id": orgdbt_model.uuid,
"source_name": orgdbt_model.source_name,
"input_name": orgdbt_model.name,
"input_type": orgdbt_model.type,
"schema": orgdbt_model.schema,
}
)
if not orgdbt_model.under_construction:
res.append(
{
"id": orgdbt_model.uuid,
"source_name": orgdbt_model.source_name,
"input_name": orgdbt_model.name,
"input_type": orgdbt_model.type,
"schema": orgdbt_model.schema,
}
)

return res

Expand Down Expand Up @@ -440,16 +441,17 @@ def get_dbt_project_DAG(request):

res_nodes = []
for node in model_nodes:
res_nodes.append(
{
"id": node.uuid,
"source_name": node.source_name,
"input_name": node.name,
"input_type": node.type,
"schema": node.schema,
"type": "src_model_node",
}
)
if not node.under_construction:
res_nodes.append(
{
"id": node.uuid,
"source_name": node.source_name,
"input_name": node.name,
"input_type": node.type,
"schema": node.schema,
"type": "src_model_node",
}
)

for node in operation_nodes:
res_nodes.append(
Expand All @@ -470,3 +472,73 @@ def get_dbt_project_DAG(request):
res["edges"] = res_edges

return res


@transformapi.delete("/dbt_project/model/{model_uuid}/", auth=auth.CanManagePipelines())
def delete_model(request, model_uuid):
"""
Delete a model if it does not have any operations chained
Convert the model to "under_construction if its has atleast 1 operation chained"
"""
orguser: OrgUser = request.orguser
org = orguser.org

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, gitrepo_url=None).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

orgdbt_model = OrgDbtModel.objects.filter(uuid=model_uuid).first()
if not orgdbt_model:
raise HttpError(404, "model not found")

operations = OrgDbtOperation.objects.filter(dbtmodel=orgdbt_model).count()

if operations > 0:
orgdbt_model.under_construction = True
orgdbt_model.save()

# delete the model file is present
dbtautomation_service.delete_dbt_model_in_project(orgdbt_model)

return {"success": 1}


@transformapi.delete(
"/dbt_project/model/operations/{operation_uuid}/", auth=auth.CanManagePipelines()
)
def delete_operation(request, operation_uuid):
"""
Delete an operation;
Delete the model if its the last operation left in the chain
"""
orguser: OrgUser = request.orguser
org = orguser.org

org_warehouse = OrgWarehouse.objects.filter(org=org).first()
if not org_warehouse:
raise HttpError(404, "please setup your warehouse first")

# make sure the orgdbt here is the one we create locally
orgdbt = OrgDbt.objects.filter(org=org, gitrepo_url=None).first()
if not orgdbt:
raise HttpError(404, "dbt workspace not setup")

dbt_operation = OrgDbtOperation.objects.filter(uuid=operation_uuid).first()
if not dbt_operation:
raise HttpError(404, "operation not found")

if OrgDbtOperation.objects.filter(dbtmodel=dbt_operation.dbtmodel).count() == 1:
# delete the model file
dbt_operation.dbtmodel.delete()
else:
dbt_operation.delete()

# delete the model file is present
dbtautomation_service.delete_dbt_model_in_project(dbt_operation.dbtmodel)

return {"success": 1}
7 changes: 7 additions & 0 deletions ddpui/core/dbtautomation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ def get_output_cols_for_operation(
_get_merge_operation_config(operations), wclient
)
return output_cols


def delete_dbt_model_in_project(orgdbt_model: OrgDbtModel):
"""Delete a dbt model in the project"""
dbt_project = dbtProject(Path(orgdbt_model.orgdbt.project_dir) / "dbtrepo")
dbt_project.delete_model(orgdbt_model.sql_path)
return True

0 comments on commit 947a91e

Please sign in to comment.