Files
AIclinicalresearch/docs/01-平台基础层/07-数据库/01-Prisma迁移历史与变更日志.md
HaHafeng 6124c7abc6 docs(platform): Add database documentation system and restructure deployment docs
Completed:
- Add 6 core database documents (docs/01-平台基础层/07-数据库/)
  Architecture overview, migration history, environment comparison,
  tech debt tracking, seed data management, PostgreSQL extensions
- Restructure deployment docs: archive 20 legacy files to _archive-2025/
- Create unified daily operations manual (01-日常更新操作手册.md)
- Add pending deployment change tracker (03-待部署变更清单.md)
- Update database development standard to v3.0 (three iron rules)
- Fix Prisma schema type drift: align @db.* annotations with actual DB
  IIT: UUID/Timestamptz(6), SSA: Timestamp(6)/VarChar(20/50/100)
- Add migration: 20260227_align_schema_with_db_types (idempotent ALTER)
- Add Cursor Rule for auto-reminding deployment change documentation
- Update system status guide v6.4 with deployment and DB doc references
- Add architecture consultation docs (Prisma guide, SAE deployment guide)

Technical details:
- Manual migration due to shadow DB limitation (TD-001 in tech debt)
- Deployment docs reduced from 20+ scattered files to 3 core documents
- Cursor Rule triggers on schema.prisma, package.json, Dockerfile changes

Made-with: Cursor
2026-02-27 14:35:25 +08:00

180 lines
6.1 KiB
Markdown
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.
# Prisma 迁移历史与变更日志
> 版本: v1.0
> 更新日期: 2026-02-27
> 维护说明: 每次新增迁移后,在此文档追加记录
---
## 1. 迁移时间线总览
当前共 **14 个已应用迁移**,覆盖 2025-10 至 2026-02 的演进过程。
```
2025-10 ████ init + conversations + batch + review_tasks
2025-12 █ column_mapping
2026-01 █ system_knowledge_base
2026-02 ████████ IIT agent + CRA QC + SSA module + DeepResearch V2
+ extraction template + db push drift patch
+ eQuery/critical events + type alignment
```
---
## 2. 完整迁移清单
### #1 — 20251010075003_init
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-01-26 08:17:06 |
| 影响 Schema | public, platform_schema, aia_schema, pkb_schema, dc_schema, iit_schema, asl_schema, ekb_schema, agent_schema |
| 核心内容 | 系统初始化,创建全部 schema + 核心表users, tenants, conversations, knowledge_bases, documents, screening_projects, literatures, agent_definitions 等) |
| 说明 | 全量初始化迁移,包含 pgvector 和 pg_bigm 扩展安装 |
### #2 — 20251010122727_add_conversation_metadata_deleted_at
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-01-26 08:17:14 |
| 影响 Schema | iit_schema |
| 核心内容 | conversation_history 表增加 metadata(JSONB) 和 deleted_at(TIMESTAMP) 列 |
### #3 — 20251012124747_add_batch_processing_module
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-01-26 08:17:16 |
| 影响 Schema | pkb_schema |
| 核心内容 | 新增 batch_tasks 和 batch_results 表,支持批处理功能 |
### #4 — 20251014120128_add_review_tasks
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-01-26 08:17:17 |
| 影响 Schema | rvw_schema |
| 核心内容 | 创建 rvw_schema 和 review_tasks 表 |
### #5 — 20251208_add_column_mapping
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-01-26 08:17:19 |
| 影响 Schema | dc_schema |
| 核心内容 | dc_extraction_tasks 表增加 column_mapping(JSONB) 列 |
### #6 — 20260128_add_system_knowledge_base
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-01-28 12:36:17 |
| 影响 Schema | capability_schema |
| 核心内容 | 创建 system_knowledge_bases 和 system_kb_documents 表,支持系统级知识库管理 |
### #7 — 20260207112544_add_iit_manager_agent_tables
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-07 03:26:29 |
| 影响 Schema | iit_schema |
| 核心内容 | IIT Manager Agent V2.x 表结构record_summary, weekly_reports, project_memory, agent_trace, skills, pii_audit_log, qc_project_stats 等 |
### #8 — 20260208134925_add_cra_qc_engine_support
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-08 05:49:47 |
| 影响 Schema | iit_schema |
| 核心内容 | CRA 质控引擎支持qc_logs, qc_reports, form_templates 表 + projects 表增加质控相关列 |
### #9 — 20260219_add_ssa_module
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-19 06:21:29 |
| 影响 Schema | ssa_schema |
| 核心内容 | 创建 ssa_schema 及 9 张表ssa_sessions, ssa_messages, ssa_execution_logs, ssa_tools_library, ssa_r_code_library, ssa_decision_table, ssa_guardrail_config, ssa_param_mapping, ssa_interpretation_templates |
### #10 — 20260223_add_deep_research_v2_fields
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-23 01:44:19 |
| 影响 Schema | asl_schema |
| 核心内容 | research_tasks 表增加 6 列target_sources, confirmed_requirement, ai_intent_summary, execution_logs, synthesis_report, result_list |
| ⚠️ 注意 | 此迁移依赖 research_tasks 表(由 prisma db push 创建Shadow DB 重放会失败 |
### #11 — 20260225_add_extraction_template_engine
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-25 00:07:57 |
| 影响 Schema | asl_schema |
| 核心内容 | 全文提取模板引擎extraction_templates, extraction_project_templates, extraction_tasks, extraction_results 4 张表 |
### #12 — 20260227_patch_db_push_drift
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-27 01:11:55 |
| 影响 Schema | iit_schema, ssa_schema, rvw_schema |
| 核心内容 | 补丁迁移,覆盖 prisma db push 创建的结构field_metadata, qc_logs, qc_reports, form_templatesiit, ssa_workflows, ssa_workflow_stepsssa, review_tasks 新增 8 列 + 1 索引rvw |
| 性质 | 使用 `CREATE TABLE IF NOT EXISTS``ADD COLUMN IF NOT EXISTS` 保证幂等 |
### #13 — 20260226_add_equery_critical_events_cron
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-27 01:12:08 |
| 影响 Schema | iit_schema |
| 核心内容 | eQuery 电子质疑表 + critical_events 重大事件表 + projects 增加 cron_enabled/cron_expression 列 |
| 特殊类型 | id 使用 PostgreSQL 原生 UUID时间戳使用 TIMESTAMPTZ |
### #14 — 20260227_align_schema_with_db_types
| 属性 | 值 |
|------|-----|
| 应用时间 | 2026-02-27 05:44:11 |
| 影响 Schema | ssa_schema |
| 核心内容 | 对齐 Schema 类型注解与数据库实际类型ssa_workflows/ssa_workflow_steps 的 VARCHAR 长度和 TIMESTAMP 精度 + 清理 2 个重复外键 |
| 性质 | Schema 精度对齐SQL 对实际数据库为幂等操作 |
---
## 3. 迁移创建方式说明
| 方式 | 适用场景 | 涉及迁移 |
|------|---------|---------|
| `prisma migrate dev` | 标准开发流程 | #1 ~ #9 |
| `prisma migrate dev --create-only` | 仅生成不执行 | — |
| 手动创建 + `prisma migrate resolve --applied` | Shadow DB 无法重放时 | #12, #13, #14 |
| `prisma db push` (⚠️ 非标准) | 快速原型,不产生迁移记录 | 造成了 drift patch 的必要性 |
---
## 4. 维护规则
### 新增迁移时,在本文档追加:
```markdown
### #N — YYYYMMDD_migration_name
| 属性 | 值 |
|------|-----|
| 应用时间 | YYYY-MM-DD HH:MM:SS |
| 影响 Schema | xxx_schema |
| 核心内容 | 简述变更 |
```
### 检查迁移状态:
```bash
# 查看本地已应用迁移
docker exec ai-clinical-postgres psql -U postgres -d ai_clinical_research \
-c "SELECT migration_name, finished_at FROM _prisma_migrations ORDER BY started_at;"
# 查看 RDS 已应用迁移
npx prisma migrate status
```