From 1d82ca9ba8d523c223fd09437d06b55278bcb459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 26 Feb 2026 08:13:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E6=89=A7=E8=A1=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 migrate_single_agent_mode 函数,在系统启动时自动添加 single_agent_bot_id 字段到 agent_user 表 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- routes/bot_manager.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/routes/bot_manager.py b/routes/bot_manager.py index 5fb3266..dcf8fda 100644 --- a/routes/bot_manager.py +++ b/routes/bot_manager.py @@ -1041,6 +1041,39 @@ async def migrate_add_marketplace_fields(): logger.info("Marketplace fields migration completed") +async def migrate_single_agent_mode(): + """ + 添加单智能体模式相关字段到 agent_user 表 + """ + pool = get_db_pool_manager().pool + + async with pool.connection() as conn: + async with conn.cursor() as cursor: + # 检查 single_agent_bot_id 字段是否存在 + await cursor.execute(""" + SELECT column_name + FROM information_schema.columns + WHERE table_name = 'agent_user' AND column_name = 'single_agent_bot_id' + """) + has_single_agent_bot_id = await cursor.fetchone() + + if not has_single_agent_bot_id: + logger.info("Adding single_agent_bot_id column to agent_user table") + await cursor.execute(""" + ALTER TABLE agent_user + ADD COLUMN single_agent_bot_id UUID + """) + await cursor.execute(""" + CREATE INDEX IF NOT EXISTS idx_agent_user_single_agent_bot + ON agent_user(single_agent_bot_id) WHERE single_agent_bot_id IS NOT NULL + """) + logger.info("Single agent mode migration completed") + else: + logger.info("single_agent_bot_id column already exists") + + await conn.commit() + + async def init_bot_manager_tables(): """ 初始化 Bot Manager 相关的所有数据库表 @@ -1054,6 +1087,8 @@ async def init_bot_manager_tables(): await migrate_bot_owner_and_shares() # 3. Marketplace 字段迁移 await migrate_add_marketplace_fields() + # 4. Single Agent Mode 字段迁移 + await migrate_single_agent_mode() # SQL 表创建语句 tables_sql = [