muse-agent-example/db/表映射.md

60 lines
4.7 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.

# muse-example 表 ↔ 主仓迁移来源映射(A2 审查面)
> 口径(创始人拍板③ 2026-07-10):主仓表**原样不改列**;实验私货全进 `example_*` 前缀。
> 建表方式:`db/ddl/` 下文件经 db skill `apply`,主仓部分为 `muse-cloud/sql/muse/` 原文拷贝或逐字摘录。
> 应用顺序:V1 → V3 → V5 → 90-ALTER摘录 → V26 → 91-example。已于 2026-07-13 应用,共 **24 张表**。
## 主仓一致表(20 张)
| 表 | 来源迁移 | 叠加的 ALTER | 实验角色 |
|---|---|---|---|
| muse_content_work | V1 | — | 参考书/未来新作的作品行(B1 导入) |
| muse_content_chapter | V1 | V26(order 唯一键改 partial) | 分章行(B1 导入) |
| muse_content_block | V1 | V26(同上) | 章正文载体(一章一 block,content_text) |
| muse_content_block_source_attribution | V1 | V30(authorization_snapshot_id→varchar(128)) | 暂空置;C 线来源归因 |
| muse_content_import_task | V1 | — | B1 导入任务审计 |
| muse_content_export_task | V1 | V9(+4 列) | 暂空置;C9 导出 |
| muse_content_command_log | V1 | — | 写命令幂等审计(import/confirm 用) |
| muse_meta_schema | V3 | — | 23 型结构本体行(A3 入库) |
| muse_meta_schema_version | V3 | V10(active 唯一索引) | 型版本(A3:每型 v1 active) |
| muse_meta_field | V3 | — | 逐型字段合同行(A3 入库) |
| muse_meta_visibility_policy | V3 | — | aiContext 控制项落点(A3 入库) |
| muse_meta_protection_node | V3 | V10(+6 列) | 保护节点登记(read-context/confirm/judge) |
| muse_meta_function_chain | V3 | — | 功能链登记(meta/chains 的库内影子,随需入库) |
| muse_knowledge_base | V5 | — | 私有参考书库 + 公共范式库(kb 行) |
| muse_knowledge_document | V5 | — | 参考书原文档案指针(storage_ref 指仓内路径) |
| muse_knowledge_document_version | V5 | — | 暂空置 |
| muse_knowledge_entity | V5 | — | **已确认**知识行(B5 确认后落此) |
| muse_knowledge_relation | V5 | — | 知识行间关系(二轮再启用) |
| muse_knowledge_draft | V5 | V14(两快照列→varchar(128)) | **草稿**知识行(B2 拆书产出落此) |
| muse_knowledge_binding | V5 | V14(同上) | 作品↔库绑定(C3 起用) |
## 实验私货表(6 张,`db/ddl/91-example实验私货.sql` + 92 + 93)
| 表 | 用途 |
|---|---|
| example_reference_work | 参考书档案(reference_work 型的库内实例载体):作者/章数对账/拆书范围与状态 |
| example_parse_task | 拆书任务状态机(一章一行,scaffold/pattern 两阶段状态)——workflow 断点续跑与幂等 |
| example_parse_scaffold | 逐章脚手架:逆推细纲(3–5%)+ 实体清单 JSONB |
| example_knowledge_embedding | 知识行嵌入边表:vector(1024)+HNSW(余弦),content_hash 幂等,挂 draft 或 entity |
| example_clean_log | 清洗审计(92):每次删除一行(原文/理由/模型/批次),源 txt 不动可回放 |
| example_parse_outline | 窗级大纲聚合(93):5–10万字窗(细纲+正文)→阶段大纲;终检=细纲对账+跨段纵览 |
## 暂缓建表登记(主仓有、实验现阶段未建;需要时按原样加建)
| 迁移 | 表 | 暂缓原因 |
|---|---|---|
| V9 | muse_content_planning_section / governance_action | C2 规划确认时加建 planning_section |
| V10 | meta 治理 8 表(command/audit/validation/impact/gray/chain_version/chain_slot/chain_node) | 治理命令流实验不镜像;装配入库随阶段二 |
| V14 | knowledge RAGFlow/治理 14 表 | 实验用 pgvector 自持嵌入,不接 RAGFlow |
| V18/V21 | 两张 event_publish_outbox | 事件出箱不镜像 |
| V25/V28/V32/V36/V37 | field_snapshot / asset_use_precheck / block_revision_snapshot / ai_generated_fulltext / task 批次列 | 对应场景(用量投影/市场/版本快照/SSE 瞬态)不在实验闭环内 |
## 实验写入约定
- `tenant_id=1`、`creator='1'`、`owner_user_id=1`(系统主账号)——写入层统一给值;列默认仍照主仓(0/''),不改列。
- 公共范式的全局知识行:`work_id=0` + `scope='global'` + 挂 `kb_type='global'` 的库;参考书私有库 `kb_type='user'`。
- 软删照主仓:`deleted=TRUE`,不物理删。**例外**:meta 种子行(`muse_meta_field`)幂等重跑=删旧插新(种子演练场景,豁免软删)。
- meta 字段行 sort_order 段位约定:1–9 基础字段,11 起特有字段。
- 双轨对应:B2 产出全落 `muse_knowledge_draft(status='pending')`;B5 管理员确认(仅创始人触发)= draft 翻 `confirmed` + 落 `muse_knowledge_entity(status='active')`;丢弃= draft 翻 `ignored`。