fix: cascade delete uses correct column names (tenant_id), remove non-existent pipeline_project_agents

This commit is contained in:
ymq 2026-08-09 22:06:53 +08:00
parent a111c056e5
commit dbef268202

View File

@ -171,16 +171,14 @@ async def _exec_tool(sor, tool, params, ctx, uid, org_id):
proj = await _find_project(sor, name)
if not proj: return f'FAIL: 项目「{name}」不存在'
pid = proj.id
# 级联删除关联数据
# 级联删除关联数据表名及对应的project关联字段
tables = [
('pipeline_deliverables', 'project_id'),
('pipeline_tasks', 'tenant_id'),
('pipeline_agent_questions', 'project_id'),
('pipeline_project_agents', 'project_id'),
('pipeline_agent_questions', 'tenant_id'),
('sd_project_repos', 'project_id'),
('sd_iterations', 'project_id'),
('sd_bugs', 'iteration_id IN (SELECT id FROM sd_iterations WHERE project_id=${p}$)'),
('pipeline_conversations', '1=0'), # conversations not directly project-scoped
]
count = 0
for tbl, cond in tables:
@ -220,8 +218,8 @@ async def _exec_tool(sor, tool, params, ctx, uid, org_id):
t = ts[0]; return f"[{t.state}][{t.role}] {t.title}"
ts = await sor.sqlExe("SELECT state,count(*)c FROM pipeline_tasks WHERE tenant_id=${p}$ GROUP BY state",{"p":ctx['pid']})
summary = ', '.join([f"{r.state}:{r.c}" for r in (ts or [])]) or '无'
ags = await sor.sqlExe("SELECT role_name,status FROM pipeline_project_agents WHERE project_id=${p}$",{"p":ctx['pid']})
al = ', '.join([f"{r.role_name}({r.status})" for r in (ags or [])]) or '未配置'
ags = await sor.sqlExe("SELECT role,count(*)c FROM pipeline_tasks WHERE tenant_id=${p}$ AND state IN ('submitted','running') GROUP BY role",{"p":ctx['pid']})
al = ', '.join([f"{getattr(r,'role','')}:{getattr(r,'c','')}" for r in (ags or [])]) or '无活跃任务'
ds = await sor.sqlExe("SELECT deliverable_type,title,review_status FROM pipeline_deliverables WHERE project_id=${p}$ ORDER BY created_at DESC LIMIT 3",{"p":ctx['pid']})
dl = '\n'.join([str(d.deliverable_type)+' '+str(d.title)[:40] for d in (ds or [])]) or '无'
return f"任务: {summary}\nAgent: {al}\n交付:\n{dl}"