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
This commit is contained in:
2026-02-27 14:35:25 +08:00
parent 9b8490b4d0
commit 6124c7abc6
48 changed files with 3009 additions and 582 deletions

View File

@@ -0,0 +1,163 @@
# 数据库架构总览
> 版本: v1.0
> 更新日期: 2026-02-27
> 数据来源: 本地开发数据库实时查询
---
## 1. 基本信息
| 项目 | 值 |
|------|-----|
| 数据库引擎 | PostgreSQL 15.15 |
| ORM | Prisma 6.17.0 |
| 数据库名 | ai_clinical_research |
| Schema 数量 | 14 个(含 public |
| 表总数 | 96 张 |
| 列总数 | 1217 个 |
| 索引总数 | 339 个 |
| 外键关系 | 53 条 |
| 扩展 | pgvector 0.8.1, pg_bigm 1.2 |
| 迁移历史 | 14 个已应用迁移 |
---
## 2. Schema 全景图
```
AI 临床研究平台 — 数据库 Schema 全景图
┌─────────────────────────────────────────────────────────────────────────┐
│ platform_schema (19 表) │
│ 用户、租户、权限、模块、pg-boss 队列 │
│ tenants → users → tenant_members → departments │
│ modules → permissions → role_permissions → user_modules │
│ job / queue / schedule / subscription (pg-boss 异步任务) │
├─────────────────────────────────────────────────────────────────────────┤
│ capability_schema (4 表) │
│ Prompt 模板管理 + 系统知识库 │
│ prompt_templates → prompt_versions │
│ system_knowledge_bases → system_kb_documents │
├─────────────────────────────────────────────────────────────────────────┤
│ agent_schema (6 表) │ ekb_schema (3 表) │
│ 通用 Agent 定义/编排/追踪 │ 企业知识库(向量) │
│ agent_definitions │ ekb_knowledge_base │
│ → agent_stages │ → ekb_document │
│ → agent_prompts │ → ekb_chunk (vector 1024) │
│ → agent_sessions │ │
│ → agent_traces │ │
│ → reflexion_rules │ │
├───────────────────────────────┴────────────────────────────────────────┤
│ admin_schema (2 表) │
│ 运营管理admin_operation_logs, simple_logs │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌── 业务模块层 ──────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ iit_schema (20 表) │ ssa_schema (11 表) │ │
│ │ IIT 临床试验管理 Agent │ 智能统计分析 │ │
│ │ projects (中心) │ ssa_sessions (中心) │ │
│ │ → conversation_history │ → ssa_messages │ │
│ │ → audit_logs │ → ssa_execution_logs │ │
│ │ → pending_actions │ → ssa_workflows │ │
│ │ → task_runs │ → ssa_workflow_steps │ │
│ │ → user_mappings │ ssa_tools_library (vector 1024) │ │
│ │ field_metadata, qc_logs │ ssa_r_code_library │ │
│ │ equery, critical_events │ ssa_decision_table │ │
│ │ skills, weekly_reports │ ssa_guardrail_config │ │
│ │ agent_trace, record_summary│ ssa_param_mapping │ │
│ │ qc_reports, qc_project_stats│ ssa_interpretation_templates │ │
│ │ │ │ │
│ │ asl_schema (11 表) │ rvw_schema (1 表) │ │
│ │ AI 智能文献 │ 稿件审查 │ │
│ │ screening_projects (中心) │ review_tasks │ │
│ │ → literatures │ │ │
│ │ → screening_tasks │ dc_schema (6 表) │ │
│ │ → screening_results │ 数据清洗整理 │ │
│ │ → fulltext_screening_* │ dc_templates │ │
│ │ research_tasks │ → dc_extraction_tasks │ │
│ │ extraction_templates │ → dc_extraction_items │ │
│ │ → extraction_project_* │ dc_tool_c_sessions │ │
│ │ → extraction_tasks │ dc_tool_c_ai_history │ │
│ │ → extraction_results│ dc_health_checks │ │
│ │ │ │ │
│ │ aia_schema (3 表) │ protocol_schema (2 表) │ │
│ │ AI 智能问答 │ 方案 Agent │ │
│ │ projects → conversations │ protocol_contexts │ │
│ │ → messages │ → protocol_generations │ │
│ │ │ │ │
│ │ pkb_schema (5 表) │ public (3 表) │ │
│ │ 个人知识库 │ _prisma_migrations │ │
│ │ knowledge_bases │ users (遗留), admin_logs (遗留) │ │
│ │ → documents │ │ │
│ │ → batch_tasks │ │ │
│ │ → batch_results │ │ │
│ │ task_templates │ │ │
│ └─────────────────────────────┴──────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
```
---
## 3. Schema 清单
| # | Schema | 表数 | 列数 | 归属模块 | 职责描述 |
|---|--------|------|------|----------|---------|
| 1 | `platform_schema` | 19 | ~200 | 平台基础层 | 用户、租户、权限、pg-boss 任务队列 |
| 2 | `capability_schema` | 4 | ~38 | 通用能力层 | Prompt 模板管理、系统知识库 |
| 3 | `agent_schema` | 6 | ~71 | 通用能力层 | 通用 Agent 定义、编排、运行追踪 |
| 4 | `ekb_schema` | 3 | ~38 | 通用能力层 | 企业知识库(向量检索) |
| 5 | `admin_schema` | 2 | ~21 | 运营管理 | 操作日志、简单日志 |
| 6 | `iit_schema` | 20 | ~246 | IIT Manager Agent | 项目管理、质控、eQuery、重大事件 |
| 7 | `ssa_schema` | 11 | ~117 | 智能统计分析 | 会话、工作流、工具库、R 代码库 |
| 8 | `asl_schema` | 11 | ~235 | AI 智能文献 | 文献筛选、全文复筛、数据提取 |
| 9 | `rvw_schema` | 1 | ~26 | 稿件审查 | 审查任务 |
| 10 | `dc_schema` | 6 | ~83 | 数据清洗 | 模板、提取任务、AI 对话 |
| 11 | `aia_schema` | 3 | ~32 | AI 智能问答 | 项目、对话、消息 |
| 12 | `protocol_schema` | 2 | ~29 | 方案 Agent | 方案上下文、方案生成 |
| 13 | `pkb_schema` | 5 | ~66 | 个人知识库 | 知识库、文档、批处理 |
| 14 | `public` | 3 | ~31 | 系统/遗留 | Prisma 迁移表 + 遗留 users/admin_logs |
**合计14 个 Schema96 张表,~1217 列**
---
## 4. 向量检索表
| Schema | 表 | 向量列 | 维度 | 用途 |
|--------|-----|--------|------|------|
| `iit_schema` | `conversation_history` | `embedding` | 1536 | IIT 对话语义搜索 |
| `ekb_schema` | `ekb_chunk` | `embedding` | 1024 | 企业知识库 RAG 检索 |
| `ssa_schema` | `ssa_tools_library` | `embedding` | 1024 | SSA 工具语义匹配 |
---
## 5. pg-boss 任务队列表
`platform_schema` 中有 5 张 pg-boss 管理的表:
| 表 | 职责 |
|-----|------|
| `job` | 活跃任务 |
| `job_common` | 公共任务配置 |
| `queue` | 队列定义 |
| `schedule` | 定时任务调度 |
| `subscription` | 事件订阅 |
> 详细使用指南见 `docs/07-运维文档/01-PgBoss队列监控与维护.md`
---
## 6. 跨文档索引
| 关注点 | 文档位置 |
|--------|---------|
| 数据库开发规范 | `docs/04-开发规范/09-数据库开发规范.md` |
| 迁移历史 | `docs/01-平台基础层/07-数据库/01-Prisma迁移历史与变更日志.md` |
| 环境差异 | `docs/01-平台基础层/07-数据库/02-环境状态对照表.md` |
| 技术债务 | `docs/01-平台基础层/07-数据库/03-技术债务追踪.md` |
| 种子数据 | `docs/01-平台基础层/07-数据库/04-种子数据管理.md` |
| 扩展特性 | `docs/01-平台基础层/07-数据库/05-PostgreSQL扩展与特性.md` |
| 部署迁移 | `docs/05-部署文档/*/01-数据库迁移方案.md` |
| 运维注意事项 | `docs/07-运维文档/03-数据库迁移注意事项.md` |
| Prisma 操作指南 | `docs/09-架构实施/J技术架构咨询/数据库同步规范与Prisma操作指南.md` |