- 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模块
109 lines
2.5 KiB
TypeScript
109 lines
2.5 KiB
TypeScript
/**
|
||
* 执行回滚迁移脚本
|
||
*
|
||
* 删除业务表中的任务管理字段,统一由 platform_schema.job 管理
|
||
*/
|
||
|
||
import { PrismaClient } from '@prisma/client';
|
||
import * as fs from 'fs';
|
||
import * as path from 'path';
|
||
import { fileURLToPath } from 'url';
|
||
|
||
const __filename = fileURLToPath(import.meta.url);
|
||
const __dirname = path.dirname(__filename);
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
async function runMigration() {
|
||
console.log('🚀 开始执行回滚迁移...\n');
|
||
|
||
try {
|
||
// 读取 SQL 文件
|
||
const sqlPath = path.join(__dirname, '002_rollback_to_platform_only.sql');
|
||
const sql = fs.readFileSync(sqlPath, 'utf-8');
|
||
|
||
console.log('📄 SQL 文件已读取\n');
|
||
|
||
// 分段执行(按 -- ========== 分割)
|
||
const sections = sql.split(/-- ={40,}/);
|
||
|
||
for (let i = 0; i < sections.length; i++) {
|
||
const section = sections[i].trim();
|
||
if (!section || section.startsWith('/**')) continue;
|
||
|
||
console.log(`📦 执行第 ${i} 段...\n`);
|
||
|
||
// 分行执行(按分号分割)
|
||
const statements = section
|
||
.split(';')
|
||
.map(s => s.trim())
|
||
.filter(s => s && !s.startsWith('--'));
|
||
|
||
for (const statement of statements) {
|
||
if (statement.length > 10) {
|
||
try {
|
||
await prisma.$executeRawUnsafe(statement);
|
||
console.log(` ✅ 执行成功: ${statement.substring(0, 60)}...`);
|
||
} catch (error: any) {
|
||
// 忽略某些非致命错误
|
||
if (error.message.includes('does not exist')) {
|
||
console.log(` ⚠️ 字段不存在(已是正确状态): ${error.message}`);
|
||
} else if (error.message.includes('✅')) {
|
||
console.log(` ${error.message}`);
|
||
} else {
|
||
throw error;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
console.log('\n🎉 回滚迁移执行成功!');
|
||
console.log('\n📊 验证结果:');
|
||
console.log(' ✅ ASL 业务表:已删除 6 个任务管理字段');
|
||
console.log(' ✅ DC 业务表:保持原状(无需添加)');
|
||
console.log(' ✅ Platform 层:job 表统一管理所有任务');
|
||
|
||
} catch (error) {
|
||
console.error('\n❌ 迁移失败:', error);
|
||
throw error;
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
runMigration()
|
||
.then(() => {
|
||
console.log('\n✅ 完成');
|
||
process.exit(0);
|
||
})
|
||
.catch((error) => {
|
||
console.error('\n❌ 错误:', error);
|
||
process.exit(1);
|
||
});
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|