在删除用户前,先删除该用户及其子账号拥有的所有 bots(agent_bots 表的 ON DELETE CASCADE 会自动清理关联的
agent_mcp_servers、agent_chat_sessions、bot_shares 记录),然后再删除用户。
This commit is contained in:
parent
85bd60cc7e
commit
e753127889
@ -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()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user