forked from xiaohei/taiji-AI-PAD
31 lines
1.2 KiB
PL/PgSQL
31 lines
1.2 KiB
PL/PgSQL
-- 迁移脚本:为 agent_billing_records 表添加回调相关字段
|
||
-- 日期:2026-01-11
|
||
-- 目的:支持 Agent Manager 回调,记录工具使用和请求信息
|
||
|
||
BEGIN;
|
||
|
||
-- 1. 添加 tools_used 字段(JSON 类型,存储使用的工具列表)
|
||
ALTER TABLE agent_billing_records
|
||
ADD COLUMN IF NOT EXISTS tools_used JSONB;
|
||
|
||
-- 2. 添加 request_id 字段(存储请求 ID)
|
||
ALTER TABLE agent_billing_records
|
||
ADD COLUMN IF NOT EXISTS request_id VARCHAR(100);
|
||
|
||
-- 3. 添加 eu_consumed 字段(如果不存在)
|
||
ALTER TABLE agent_billing_records
|
||
ADD COLUMN IF NOT EXISTS eu_consumed INTEGER DEFAULT 0;
|
||
|
||
-- 4. 为 request_id 创建索引,方便查询
|
||
CREATE INDEX IF NOT EXISTS idx_agent_billing_request_id ON agent_billing_records(request_id);
|
||
|
||
-- 5. 为 tools_used 创建 GIN 索引,支持 JSON 查询
|
||
CREATE INDEX IF NOT EXISTS idx_agent_billing_tools_used ON agent_billing_records USING gin(tools_used);
|
||
|
||
-- 6. 添加注释
|
||
COMMENT ON COLUMN agent_billing_records.tools_used IS 'Agent 使用的工具列表(JSON 数组)';
|
||
COMMENT ON COLUMN agent_billing_records.request_id IS '请求 ID,用于关联 Agent Manager 的调用';
|
||
COMMENT ON COLUMN agent_billing_records.eu_consumed IS 'EU 消耗量';
|
||
|
||
COMMIT;
|