docs: 修正测试策略 spec 的事实性错误

修正 spec review 发现的问题:
- C-1: TestDb 实际是本地 PostgreSQL 隔离,非 Testcontainers
- C-2: E2E 已有 4 spec/10 测试,非零测试
- 补充 6 个遗漏的 service(alert/daily_monitoring/critical_value_threshold 等)
- 增加 Phase 0 基础设施搭建
- 修正 CI 配置(增加 PostgreSQL service、验证链)
- 补充 5 个遗漏风险项和回退策略
- 统一"全量 80%"目标的准确含义
This commit is contained in:
iven
2026-04-27 00:21:02 +08:00
parent 8cd65f7be5
commit 5b81a0051f
33 changed files with 2380 additions and 82 deletions

View File

@@ -1,6 +1,6 @@
---
title: 数据库迁移与模式
updated: 2026-04-25
updated: 2026-04-26
status: stable
tags: [database, seaorm, migration, multi-tenant]
---
@@ -24,7 +24,7 @@ tags: [database, seaorm, migration, multi-tenant]
| 文件 | 职责 |
|------|------|
| `crates/erp-server/migration/src/lib.rs` | Migrator 注册所有迁移 |
| `crates/erp-server/migration/src/m*.rs` | 50 个迁移文件 |
| `crates/erp-server/migration/src/m*.rs` | 72 个迁移文件 |
| `crates/erp-core/src/types.rs` | BaseFields 标准字段定义 |
### 迁移命名规则
@@ -34,34 +34,53 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
例: m20260410_000001_create_tenant.rs
```
### 当前表概览(48 张)
### 当前表概览(67+ 张)
| 模块 | 表 |
|------|-----|
| 基础 | tenant |
| 基础 | tenant, tenant_crypto_keys |
| 认证 (auth) | users, user_credentials, user_tokens, roles, permissions, role_permissions, user_roles, organizations, departments, positions, user_departments |
| 配置 (config) | dictionaries, dictionary_items, menus, menu_roles, settings, numbering_rules |
| 工作流 (workflow) | process_definitions, process_instances, tokens, tasks, process_variables |
| 消息 (message) | message_templates, messages, message_subscriptions |
| 审计 | audit_logs, domain_events |
| 插件 (plugin) | plugins, entity_registry, plugin_market, plugin_user_views |
| **健康 (health)** | patient, patient_family_member, patient_tag, patient_tag_relation, patient_doctor_relation, doctor_profile, health_record, vital_signs, lab_report, health_trend, appointment, doctor_schedule, follow_up_task, follow_up_record, consultation_session, consultation_message |
| **健康 (health)** | patient, patient_family_member, patient_tag, patient_tag_relation, patient_doctor_relation, doctor_profile, health_record, vital_signs, daily_monitoring, lab_report, health_trend, diagnosis, dialysis_record, critical_value_thresholds, consent, appointment, doctor_schedule, follow_up_task, follow_up_record, consultation_session, consultation_message |
| **内容 (article)** | article, article_category, article_tag, article_article_tag, article_revision |
| **积分 (points)** | points_account, points_rule, points_product, points_order, points_transaction, points_checkin |
| **线下活动** | offline_event, offline_event_registration |
| **AI (ai)** | ai_prompt, ai_analysis, ai_usage |
| **微信 (wechat)** | wechat_users |
| **内容 (article)** | article |
### 健康模块迁移m000042 - m000050
### 健康模块迁移m000042 - m000072
| 迁移 | 变更 |
|------|------|
| m000042 | 创建 17 张健康业务表patient/doctor/appointment/schedule/vital_signs/lab_report/health_record/health_trend/follow_up_task/follow_up_record/consultation_session/consultation_message/patient_tag/patient_tag_relation/patient_family_member/patient_doctor_relation |
| m000042 | 创建 17 张健康业务表 |
| m000043 | 创建 wechat_users 表 |
| m000044 | 创建 article 表 |
| m000045 | 健康模块索引优化 |
| m000046 | 健康模块约束修复 |
| m000047 | 健康模块索引修复 |
| m000048 | 添加 patient.id_number_hash 列HMAC-SHA256 哈希身份证) |
| m000049 | 拓宽 patient.id_number 列VARCHAR 加密存储需要更长字段) |
| m000050 | 添加 appointment.doctor_name 列(冗余提升查询性能) |
| m000048 | 添加 patient.id_number_hash 列 |
| m000049 | 拓宽 patient.id_number 列 |
| m000050 | 添加 appointment.doctor_name 列 |
| m000051 | 透析/化验增强字段 |
| m000052 | 创建 AI 分析表ai_prompt/ai_analysis/ai_usage |
| m000053 | 创建积分商城表points_account/rule/product/order/transaction |
| m000054 | 创建日常监测表daily_monitoring |
| m000055 | 积分签到标准字段 |
| m000056 | 创建诊断表diagnosis |
| m000057 | 重命名 points_transaction 类型列 |
| m000058 | 合并 daily_monitoring 到 vital_signs |
| m000059 | 种子菜单数据 |
| m000060 | 创建危急值阈值表 |
| m000061 | 创建知情同意表 |
| m000062 | 创建租户加密密钥表tenant_crypto_keys |
| m000063 | 内容管理表article_category/article_tag/article_article_tag/article_revision |
| m000064-000068 | PII 加密扩展patient/consultation/follow_up/family_member/doctor_profile |
| m000069-000071 | 加密字段 key_versiondialysis_record/lab_report/diagnosis |
| m000072 | 拓宽加密手机号列 |
### 集成契约
@@ -70,7 +89,7 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
| 消费 ← | [[erp-server]] | 启动时自动运行 `Migrator::up()` |
| 依赖 ← | [[erp-core]] | BaseFields 定义标准字段规范 |
| 提供 → | 所有业务模块 | 表结构供 SeaORM Entity 使用 |
| 提供 → | [[erp-health]] | 18 张健康业务表 |
| 提供 → | [[erp-health]] | 34 张健康业务表 |
## 3. 代码逻辑
@@ -112,6 +131,7 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
| 日期 | 变更 |
|------|------|
| 2026-04-26 | 更新至 72 迁移、67+ 表,新增积分商城/透析/诊断/内容管理/线下活动/PII 加密扩展等 22 个迁移 |
| 2026-04-25 | 更新至 50 迁移、48 表新增健康模块迁移m000042-m000050和 18 张健康业务表 |
| 2026-04-23 | 重构为 5 节结构,更新表清单至 41 个迁移 |
| 2026-04-19 | CRM 权限码修复迁移 (m000038) |