Files
AIclinicalresearch/docs/01-平台基础层/07-数据库/04-种子数据管理.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

117 lines
4.2 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.
# 种子数据管理
> 版本: v1.0
> 更新日期: 2026-02-27
> 维护说明: 新增种子数据类型时,在此文档登记
---
## 1. 什么是种子数据
种子数据Seed Data是系统正常运行所必需的初始/模板数据。与用户产生的业务数据不同,种子数据:
- 在新环境部署时必须初始化
- 在版本升级时可能需要同步更新
- 跨环境需要保持一致(或有明确的差异策略)
---
## 2. 种子数据清单
### 2.1 Prompt 模板capability_schema
| 表 | 数据内容 | 同步策略 | 说明 |
|-----|---------|---------|------|
| `prompt_templates` | Prompt 定义SSA_BASE_SYSTEM, SSA_INTENT_ANALYZE 等) | 手动同步 | 每个模块的 AI Prompt 模板 |
| `prompt_versions` | 各 Prompt 的版本记录v1, v2, ACTIVE 标记) | 跟随模板同步 | 支持版本回退 |
**当前 Prompt 列表**(需跨环境同步的关键项):
| Prompt Key | 所属模块 | 说明 |
|------------|---------|------|
| SSA_BASE_SYSTEM | SSA | SSA 基础系统 Prompt |
| SSA_INTENT_ANALYZE | SSA | SSA 意图分析 Prompt |
| IIT_* | IIT | IIT Agent 系列 Prompt |
| RVW_* | RVW | 稿件审查系列 Prompt |
| AIA_* | AIA | AI 智能问答 Prompt |
| PROTOCOL_* | Protocol | 方案 Agent Prompt |
> 完整 Prompt 清单维护在运营管理后台,此处仅列出关键类别。
### 2.2 SSA 工具库ssa_schema
| 表 | 数据内容 | 同步策略 | 说明 |
|-----|---------|---------|------|
| `ssa_tools_library` | 统计工具定义13 个工具) | SQL INSERT 脚本 | 含 tool_code, params_schema, guardrails 等 |
| `ssa_decision_table` | 统计方法决策表 | SQL INSERT 脚本 | 根据数据特征选择分析方法的规则 |
| `ssa_guardrail_config` | 护栏配置 | SQL INSERT 脚本 | 各工具的前置检验规则 |
| `ssa_param_mapping` | 参数映射 | SQL INSERT 脚本 | LLM 输出到 R 参数的映射 |
| `ssa_interpretation_templates` | 解释模板 | SQL INSERT 脚本 | 统计结果的自然语言解释模板 |
| `ssa_r_code_library` | R 代码模板 | SQL INSERT 脚本 | 13 个统计工具的 R 代码片段 |
### 2.3 Agent 定义agent_schema
| 表 | 数据内容 | 同步策略 | 说明 |
|-----|---------|---------|------|
| `agent_definitions` | Agent 类型定义 | 手动同步 | IIT Agent、Protocol Agent 等 |
| `agent_stages` | Agent 运行阶段定义 | 跟随 agent 同步 | |
| `reflexion_rules` | Agent 反思规则 | 跟随 agent 同步 | |
### 2.4 平台基础数据platform_schema
| 表 | 数据内容 | 同步策略 | 说明 |
|-----|---------|---------|------|
| `modules` | 系统模块定义 | 代码内置 | AIA, IIT, ASL, SSA, RVW, DC, PKB 等 |
| `permissions` | 权限定义 | 代码内置 | 各模块的操作权限 |
| `tenants` | 初始租户 | 首次部署时创建 | 至少一个默认租户 |
| `users` | 管理员账号 | 首次部署时创建 | 超级管理员 |
---
## 3. 同步操作指南
### 3.1 新环境初始化
```bash
# 1. 运行 Prisma 迁移(创建表结构)
npx prisma migrate deploy
# 2. 运行种子脚本(插入种子数据)
npx prisma db seed
# 或手动执行 SQL 脚本
```
### 3.2 版本升级时同步
```bash
# 1. 检查本次升级是否涉及种子数据变更
# 查看 docs/01-平台基础层/07-数据库/01-Prisma迁移历史与变更日志.md
# 2. 如有新增 Prompt 或工具定义,准备 INSERT 脚本
# 3. 在目标环境执行 INSERT ... ON CONFLICT DO UPDATE
```
### 3.3 Prompt 同步注意事项
- Prompt 数据由**运营管理后台**管理ADMIN 模块)
- 开发环境的 Prompt 可能带有调试版本,同步到生产前需确认使用 ACTIVE 版本
- 知识库配置system_knowledge_bases跟随 Prompt 同步
---
## 4. 待建设项
| 项目 | 优先级 | 说明 |
|------|--------|------|
| 自动化 seed 脚本 | 高 | 将关键种子数据编写为 `prisma/seed.ts`,支持 `npx prisma db seed` |
| Prompt 导出/导入工具 | 中 | 从运营管理后台导出 JSON在目标环境导入 |
| SSA 工具库 seed SQL | 中 | 将 13 个工具的定义整理为标准 INSERT 脚本 |
---
## 5. 更新日志
| 日期 | 操作人 | 变更 |
|------|--------|------|
| 2026-02-27 | AI 助手 | 初始化文档,梳理种子数据类型和同步策略 |