Files
AIclinicalresearch/backend/prisma/manual-migrations/run-migration-002.ts
HaHafeng 57fdc6ef00 feat(aia): Integrate PromptService for 10 AI agents
Features:
- Migrate 10 agent prompts from hardcoded to database
- Add grayscale preview support (DRAFT/ACTIVE distribution)
- Implement 3-tier fallback (DB -> Cache -> Hardcoded)
- Add version management and rollback capability

Files changed:
- backend/scripts/migrate-aia-prompts.ts (new migration script)
- backend/src/common/prompt/prompt.fallbacks.ts (add AIA fallbacks)
- backend/src/modules/aia/services/agentService.ts (integrate PromptService)
- backend/src/modules/aia/services/conversationService.ts (pass userId)
- backend/src/modules/aia/types/index.ts (fix AgentStage type)

Documentation:
- docs/03-业务模块/AIA-AI智能问答/06-开发记录/2026-01-18-Prompt管理系统集成.md
- docs/02-通用能力层/00-通用能力层清单.md (add FileCard, Prompt management)
- docs/00-系统总体设计/00-系统当前状态与开发指南.md (update to v3.6)

Prompt codes:
- AIA_SCIENTIFIC_QUESTION, AIA_PICO_ANALYSIS, AIA_TOPIC_EVALUATION
- AIA_OUTCOME_DESIGN, AIA_CRF_DESIGN, AIA_SAMPLE_SIZE
- AIA_PROTOCOL_WRITING, AIA_METHODOLOGY_REVIEW
- AIA_PAPER_POLISH, AIA_PAPER_TRANSLATE

Tested: Migration script executed, all 10 prompts inserted successfully
2026-01-18 15:48:53 +08:00

132 lines
2.5 KiB
TypeScript
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.
/**
* 执行回滚迁移脚本
*
* 删除业务表中的任务管理字段,统一由 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);
});