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()