mirror of https://github.com/langgenius/dify.git
chore: when delete app also delete related trigger tables
This commit is contained in:
parent
f06dc3ef90
commit
0b599b44b0
|
|
@ -69,7 +69,11 @@ def remove_app_and_related_data_task(self, tenant_id: str, app_id: str):
|
|||
_delete_trace_app_configs(tenant_id, app_id)
|
||||
_delete_conversation_variables(app_id=app_id)
|
||||
_delete_draft_variables(app_id)
|
||||
_delete_app_plugin_triggers(tenant_id, app_id)
|
||||
_delete_app_triggers(tenant_id, app_id)
|
||||
_delete_workflow_plugin_triggers(tenant_id, app_id)
|
||||
_delete_workflow_webhook_triggers(tenant_id, app_id)
|
||||
_delete_workflow_schedule_plans(tenant_id, app_id)
|
||||
_delete_workflow_trigger_logs(tenant_id, app_id)
|
||||
|
||||
end_at = time.perf_counter()
|
||||
logger.info(click.style(f"App and related data deleted: {app_id} latency: {end_at - start_at}", fg="green"))
|
||||
|
|
@ -504,11 +508,86 @@ def _delete_records(query_sql: str, params: dict, delete_func: Callable, name: s
|
|||
rs.close()
|
||||
|
||||
|
||||
def _delete_app_plugin_triggers(tenant_id: str, app_id: str):
|
||||
def _delete_app_triggers(tenant_id: str, app_id: str):
|
||||
with db.engine.begin() as conn:
|
||||
result = conn.execute(
|
||||
sa.text("DELETE FROM workflow_plugin_triggers WHERE app_id = :app_id"), {"app_id": app_id}
|
||||
sa.text(
|
||||
"""
|
||||
DELETE FROM app_triggers
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND app_id = :app_id
|
||||
"""
|
||||
),
|
||||
{"tenant_id": tenant_id, "app_id": app_id},
|
||||
)
|
||||
deleted_count = result.rowcount
|
||||
deleted_count = result.rowcount or 0
|
||||
if deleted_count > 0:
|
||||
logger.info(click.style(f"Deleted {deleted_count} app triggers for app {app_id}", fg="green"))
|
||||
|
||||
|
||||
def _delete_workflow_plugin_triggers(tenant_id: str, app_id: str):
|
||||
with db.engine.begin() as conn:
|
||||
result = conn.execute(
|
||||
sa.text(
|
||||
"""
|
||||
DELETE FROM workflow_plugin_triggers
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND app_id = :app_id
|
||||
"""
|
||||
),
|
||||
{"tenant_id": tenant_id, "app_id": app_id},
|
||||
)
|
||||
deleted_count = result.rowcount or 0
|
||||
if deleted_count > 0:
|
||||
logger.info(click.style(f"Deleted {deleted_count} workflow plugin triggers for app {app_id}", fg="green"))
|
||||
|
||||
|
||||
def _delete_workflow_webhook_triggers(tenant_id: str, app_id: str):
|
||||
with db.engine.begin() as conn:
|
||||
result = conn.execute(
|
||||
sa.text(
|
||||
"""
|
||||
DELETE FROM workflow_webhook_triggers
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND app_id = :app_id
|
||||
"""
|
||||
),
|
||||
{"tenant_id": tenant_id, "app_id": app_id},
|
||||
)
|
||||
deleted_count = result.rowcount or 0
|
||||
if deleted_count > 0:
|
||||
logger.info(click.style(f"Deleted {deleted_count} workflow webhook triggers for app {app_id}", fg="green"))
|
||||
|
||||
|
||||
def _delete_workflow_schedule_plans(tenant_id: str, app_id: str):
|
||||
with db.engine.begin() as conn:
|
||||
result = conn.execute(
|
||||
sa.text(
|
||||
"""
|
||||
DELETE FROM workflow_schedule_plans
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND app_id = :app_id
|
||||
"""
|
||||
),
|
||||
{"tenant_id": tenant_id, "app_id": app_id},
|
||||
)
|
||||
deleted_count = result.rowcount or 0
|
||||
if deleted_count > 0:
|
||||
logger.info(click.style(f"Deleted {deleted_count} workflow schedule plans for app {app_id}", fg="green"))
|
||||
|
||||
|
||||
def _delete_workflow_trigger_logs(tenant_id: str, app_id: str):
|
||||
with db.engine.begin() as conn:
|
||||
result = conn.execute(
|
||||
sa.text(
|
||||
"""
|
||||
DELETE FROM workflow_trigger_logs
|
||||
WHERE tenant_id = :tenant_id
|
||||
AND app_id = :app_id
|
||||
"""
|
||||
),
|
||||
{"tenant_id": tenant_id, "app_id": app_id},
|
||||
)
|
||||
deleted_count = result.rowcount or 0
|
||||
if deleted_count > 0:
|
||||
logger.info(click.style(f"Deleted {deleted_count} workflow trigger logs for app {app_id}", fg="green"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue