feat(release): 发布目标知识库可选(源库 → 目标库映射)

- 迁移 000044:production_kb_bindings + release_item_executions.target_knowledge_base_id
- 系统设置新增「生产知识库绑定(对内/对外)」:从生产 WeKnora 实际列表选库,
  保存时真校验(不存在拒收;生产端不可达只提示并如实回报),仅管理员可改
- 执行计划按绑定解析目标库并冻结进 release_item_executions;空目标直接拒收;
  已发布过的条目保留原目标(重试/回滚回到同一处)
- DocumentBundle.RemapKnowledgeBase:knowledges/chunks/knowledge_tags/wiki_pages/
  wiki_folders 的 knowledge_base_id 与 ES 文档字段改写为目标库,重算表/文档摘要并重新封装
- 契约比对改为「声明的映射对」(KnowledgeBaseMapping),其余字段继续 fail-closed
- 契约检查器 / 目标身份 / 验证器全部走映射后的目标库;对象通道无需改写
- Compose 拆分:数据面接线 compose.release-sim.yaml + 两道门禁 compose.release-gates.yaml
- 测试:RemapKnowledgeBase 全通道/无操作/fail-closed、映射契约、绑定接口、RBAC、真实 PG 集成
This commit is contained in:
姚章浩
2026-10-08 15:41:13 +08:00
parent cddc4c90d1
commit 6440e3f679
40 changed files with 1823 additions and 92 deletions
@@ -0,0 +1,2 @@
ALTER TABLE release_item_executions DROP COLUMN IF EXISTS target_knowledge_base_id;
DROP TABLE IF EXISTS production_kb_bindings;
@@ -0,0 +1,22 @@
-- Cross-environment release needs an explicit 源库 → 目标库 mapping. Until now
-- the production KB was forced to carry the same id as the tested KB, which
-- meant only same-id "mirror" bases could ever be published to. One row stores
-- which (production-side) knowledge base receives 对内 and which receives 对外
-- releases; an empty side keeps the historical same-id semantics (and fails
-- closed later if that id does not exist on the target).
CREATE TABLE production_kb_bindings (
id TEXT PRIMARY KEY DEFAULT 'active' CHECK (id = 'active'),
internal_kb_id VARCHAR(64) NOT NULL DEFAULT '',
external_kb_id VARCHAR(64) NOT NULL DEFAULT '',
updated_by VARCHAR(64) NOT NULL DEFAULT '',
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
INSERT INTO production_kb_bindings(id,internal_kb_id,external_kb_id,updated_by)
VALUES('active','','','system:migration');
-- The resolved target base is frozen per release item when the execution
-- starts, so an audit shows exactly where each knowledge went and a retry
-- reuses the same target instead of re-resolving a binding that may have moved.
ALTER TABLE release_item_executions
ADD COLUMN target_knowledge_base_id VARCHAR(64) NOT NULL DEFAULT '';