Files
taiji-AI-PAD/services/mcp-server/migrations/015_add_tool_template_fields.sql
T

31 lines
1.4 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 迁移脚本:添加工具模板相关字段
-- 版本:015
-- 日期:2026-01-13
-- 描述:
-- 1. 添加 template 字段到 tools 表,用于关联 Agent 模板
-- 2. 添加 env_config 字段到 tools 表,存储模板所需的环境变量配置
-- 3. 修改 schema 字段为可空(模板工具不需要 schema)
-- 4. 创建索引优化按模板类型查询
--
-- 业务背景:
-- 用户基于 Agent 模板(如 mysql_agent、postgresql_agent)创建工具时,
-- 需要保存模板名称和填写的环境变量配置(如数据库连接信息)。
-- 创建自定义 Agent 时,从工具中获取模板类型和配置。
-- 添加 template 字段(模板名称,如 "mysql_agent", "postgresql_agent")
ALTER TABLE tools ADD COLUMN IF NOT EXISTS template VARCHAR(100);
-- 添加 env_config 字段(环境变量配置,JSON 格式)
ALTER TABLE tools ADD COLUMN IF NOT EXISTS env_config JSONB DEFAULT '{}';
-- 修改 schema 字段为可空(模板工具可能没有 schema)
ALTER TABLE tools ALTER COLUMN schema DROP NOT NULL;
-- 创建索引(用于按模板类型查询工具)
CREATE INDEX IF NOT EXISTS idx_tool_template ON tools(template);
-- 添加注释
COMMENT ON COLUMN tools.template IS 'Agent 模板名称,如 mysql_agent、postgresql_agent。用于基于模板创建的工具';
COMMENT ON COLUMN tools.env_config IS '环境变量配置(JSON格式),根据模板的 env_info 填写。如 MySQL 连接信息';