From e753127889ff51a4760be29fe18d479e967a55d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Mon, 13 Apr 2026 16:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=89=8D=EF=BC=8C=E5=85=88=E5=88=A0=E9=99=A4=E8=AF=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=8A=E5=85=B6=E5=AD=90=E8=B4=A6=E5=8F=B7=E6=8B=A5?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E6=89=80=E6=9C=89=20bots=EF=BC=88agent=5Fbot?= =?UTF-8?q?s=20=E8=A1=A8=E7=9A=84=20ON=20DELETE=20CASCADE=20=E4=BC=9A?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86=E5=85=B3=E8=81=94=E7=9A=84?= =?UTF-8?q?=20=20=20agent=5Fmcp=5Fservers=E3=80=81agent=5Fchat=5Fsessions?= =?UTF-8?q?=E3=80=81bot=5Fshares=20=E8=AE=B0=E5=BD=95=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E7=84=B6=E5=90=8E=E5=86=8D=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/bot_manager.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/routes/bot_manager.py b/routes/bot_manager.py index 3b2c5c9..89dec1f 100644 --- a/routes/bot_manager.py +++ b/routes/bot_manager.py @@ -3392,6 +3392,13 @@ async def delete_user(user_id: str, authorization: Optional[str] = Header(None)) async with pool.connection() as conn: async with conn.cursor() as cursor: + # 先删除该用户及其子账号拥有的所有 bots(级联清理 mcp_servers, chat_sessions, shares) + await cursor.execute( + "DELETE FROM agent_bots WHERE owner_id = %s OR owner_id IN (SELECT id FROM agent_user WHERE parent_id = %s)", + (user_id, user_id) + ) + + # 再删除用户(子账号通过 parent_id ON DELETE CASCADE 自动删除) await cursor.execute("DELETE FROM agent_user WHERE id = %s RETURNING username", (user_id,)) row = await cursor.fetchone()