docs: 全面更新 wiki 文档至当前实现状态
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

9 个 wiki 页面全部更新:
- index: 关键数字更新(15 crate/48 表/50 迁移/6 模块)
- erp-health: 从"规划中"更新为"已实现"(18 实体/14 权限)
- erp-server: 6 模块注册/8 环境变量/5 后台任务
- database: 50 迁移/48 表/健康模块迁移(m000042-m000050)
- frontend: 10 健康路由/12 共享组件/7 健康 API/3 单元测试
- miniprogram: 20 页面/10 服务/9 组件
- testing: 93 后端测试+3 前端测试/全链路验证结果
- erp-core: 新增 erp-health 集成契约
- architecture: 6 模块实现状态表/预约 CAS/PII 加密
This commit is contained in:
iven
2026-04-25 11:57:20 +08:00
parent 355e8da272
commit 40b5141832
9 changed files with 501 additions and 70 deletions

View File

@@ -1,13 +1,13 @@
---
title: 数据库迁移与模式
updated: 2026-04-23
updated: 2026-04-25
status: stable
tags: [database, seaorm, migration, multi-tenant]
---
# 数据库迁移与模式
> 从 [[index]] 导航。关联: [[erp-core]] [[erp-server]] [[infrastructure]]
> 从 [[index]] 导航。关联: [[erp-core]] [[erp-server]] [[infrastructure]] [[erp-health]]
## 1. 设计决策
@@ -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` | 41 个迁移文件 |
| `crates/erp-server/migration/src/m*.rs` | 50 个迁移文件 |
| `crates/erp-core/src/types.rs` | BaseFields 标准字段定义 |
### 迁移命名规则
@@ -34,7 +34,7 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
例: m20260410_000001_create_tenant.rs
```
### 当前表概览(30 张)
### 当前表概览(48 张)
| 模块 | 表 |
|------|-----|
@@ -45,6 +45,23 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
| 消息 (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 |
| **微信 (wechat)** | wechat_users |
| **内容 (article)** | article |
### 健康模块迁移m000042 - m000050
| 迁移 | 变更 |
|------|------|
| 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 |
| m000043 | 创建 wechat_users 表 |
| m000044 | 创建 article 表 |
| m000045 | 健康模块索引优化 |
| m000046 | 健康模块约束修复 |
| m000047 | 健康模块索引修复 |
| m000048 | 添加 patient.id_number_hash 列HMAC-SHA256 哈希身份证) |
| m000049 | 拓宽 patient.id_number 列VARCHAR 加密存储需要更长字段) |
| m000050 | 添加 appointment.doctor_name 列(冗余提升查询性能) |
### 集成契约
@@ -53,6 +70,7 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
| 消费 ← | [[erp-server]] | 启动时自动运行 `Migrator::up()` |
| 依赖 ← | [[erp-core]] | BaseFields 定义标准字段规范 |
| 提供 → | 所有业务模块 | 表结构供 SeaORM Entity 使用 |
| 提供 → | [[erp-health]] | 18 张健康业务表 |
## 3. 代码逻辑
@@ -62,6 +80,8 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
**不变量**: 迁移执行由 erp-server 启动自动触发,不手动执行 SQL
**不变量**: 健康模块 PII 数据使用 AES-256-GCM 加密存储,身份证号额外 HMAC-SHA256 哈希
### 关键结构变更迁移
| 迁移 | 变更 |
@@ -73,6 +93,8 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
| m000038 | 修复 CRM 权限码 |
| m000039 | entity_registry 列 |
| m000041 | plugin_user_views |
| m000042 | 17 张健康业务表 |
| m000048 | patient.id_number_hash HMAC 列 |
## 4. 活跃问题 + 陷阱
@@ -80,13 +102,16 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
- 唯一索引 + 软删除冲突 — 已删除记录的 unique key 阻止新建m000027 修复)
- tenant 表缺少 `created_by`/`updated_by`/`version` 字段 — 首个迁移早于 BaseFields 规范
- wechat_users 表初始缺少标准字段列 — 需 ALTER TABLE 补充m000043 已包含完整字段)
⚠️ settings 表的唯一索引曾需修复m000032
⚠️ 新增表时务必对齐 `crates/erp-core/src/types.rs` 中的 BaseFields
⚠️ 已应用的迁移文件被删除会导致启动失败 — 需创建空 stub 迁移m000050 案例)
## 5. 变更记录
| 日期 | 变更 |
|------|------|
| 2026-04-25 | 更新至 50 迁移、48 表新增健康模块迁移m000042-m000050和 18 张健康业务表 |
| 2026-04-23 | 重构为 5 节结构,更新表清单至 41 个迁移 |
| 2026-04-19 | CRM 权限码修复迁移 (m000038) |