- feat: ChatService集成DeepSeek-V3实现AI对话(390行) - feat: SessionMemory实现上下文记忆(最近3轮对话,170行) - feat: 意图识别支持REDCap数据查询(关键词匹配) - feat: REDCap数据注入LLM(queryRedcapRecord, countRedcapRecords, getProjectInfo) - feat: 解决LLM幻觉问题(基于真实数据回答,明确system prompt) - feat: 即时反馈(正在查询...提示) - test: REDCap查询测试通过(test0102项目,10条记录,ID 7患者详情) - docs: 创建Phase1.5开发完成记录(313行) - docs: 更新Phase1.5开发计划(标记完成) - docs: 更新MVP开发任务清单(Phase 1.5完成) - docs: 更新模块当前状态(60%完成度) - docs: 更新系统总体设计文档(v2.6) - chore: 删除测试脚本(test-redcap-query-for-ai.ts, check-env-config.ts) - chore: 移除REDCap测试环境变量(REDCAP_TEST_*) 技术亮点: - AI基于REDCap真实数据对话,不编造信息 - 从数据库读取项目配置,不使用环境变量 - 企业微信端测试通过,用户体验良好 测试通过: - 查询项目记录总数(10条) - 查询特定患者详情(ID 7) - 项目信息查询 - 上下文记忆(3轮对话) - 即时反馈提示 影响范围:IIT Manager Agent模块
96 lines
2.2 KiB
SQL
96 lines
2.2 KiB
SQL
-- ==================== Postgres-Only 改造:手动迁移 ====================
|
||
-- 文件: 001_add_postgres_cache_and_checkpoint.sql
|
||
-- 目的: 添加缓存表和断点续传字段
|
||
-- 日期: 2025-12-13
|
||
-- 说明: 避免Prisma migrate的shadow database问题,手动添加所需表和字段
|
||
|
||
-- ==================== 1. 创建缓存表 (AppCache) ====================
|
||
|
||
CREATE TABLE IF NOT EXISTS platform_schema.app_cache (
|
||
id SERIAL PRIMARY KEY,
|
||
key VARCHAR(500) UNIQUE NOT NULL,
|
||
value JSONB NOT NULL,
|
||
expires_at TIMESTAMP NOT NULL,
|
||
created_at TIMESTAMP DEFAULT NOW()
|
||
);
|
||
|
||
-- 创建索引(优化过期查询和key查询)
|
||
CREATE INDEX IF NOT EXISTS idx_app_cache_expires
|
||
ON platform_schema.app_cache(expires_at);
|
||
|
||
CREATE INDEX IF NOT EXISTS idx_app_cache_key_expires
|
||
ON platform_schema.app_cache(key, expires_at);
|
||
|
||
-- ==================== 2. 为AslScreeningTask添加新字段 ====================
|
||
|
||
-- 任务拆分支持字段
|
||
ALTER TABLE asl_schema.screening_tasks
|
||
ADD COLUMN IF NOT EXISTS total_batches INTEGER DEFAULT 1,
|
||
ADD COLUMN IF NOT EXISTS processed_batches INTEGER DEFAULT 0,
|
||
ADD COLUMN IF NOT EXISTS current_batch_index INTEGER DEFAULT 0;
|
||
|
||
-- 断点续传支持字段
|
||
ALTER TABLE asl_schema.screening_tasks
|
||
ADD COLUMN IF NOT EXISTS current_index INTEGER DEFAULT 0,
|
||
ADD COLUMN IF NOT EXISTS last_checkpoint TIMESTAMP,
|
||
ADD COLUMN IF NOT EXISTS checkpoint_data JSONB;
|
||
|
||
-- ==================== 3. 验证创建结果 ====================
|
||
|
||
-- 查看app_cache表结构
|
||
SELECT
|
||
column_name,
|
||
data_type,
|
||
is_nullable,
|
||
column_default
|
||
FROM information_schema.columns
|
||
WHERE table_schema = 'platform_schema'
|
||
AND table_name = 'app_cache'
|
||
ORDER BY ordinal_position;
|
||
|
||
-- 查看screening_tasks新增字段
|
||
SELECT
|
||
column_name,
|
||
data_type,
|
||
is_nullable,
|
||
column_default
|
||
FROM information_schema.columns
|
||
WHERE table_schema = 'asl_schema'
|
||
AND table_name = 'screening_tasks'
|
||
AND column_name IN (
|
||
'total_batches', 'processed_batches', 'current_batch_index',
|
||
'current_index', 'last_checkpoint', 'checkpoint_data'
|
||
)
|
||
ORDER BY ordinal_position;
|
||
|
||
-- ==================== 完成 ====================
|
||
-- ✅ 缓存表已创建
|
||
-- ✅ 任务拆分字段已添加
|
||
-- ✅ 断点续传字段已添加
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|