- profile 新增 137(由 v090 克隆),声明知识域关联表 copied/derived/excluded 分类。 - 导出前与导入写事务内各跑漏表门禁;未声明有数据拒绝,空表警告写入 WriteSet。 - chunk_revisions/wiki_page_revisions 接入范围改写、目标身份映射、自然键与回滚顺序。
This commit is contained in:
@@ -18,6 +18,27 @@ const LegacyVersion = 74
|
||||
// V090Version 是 0.9.0 的 schema_migrations 版本号(已实测:134、dirty=false、83 表)。
|
||||
const V090Version = 134
|
||||
|
||||
// V091Version 是 0.9.1 的 schema_migrations 版本号(上游 tag v0.9.1,最大迁移 137)。
|
||||
// 135–137 只改审计列宽/凭据表/IM 唯一索引,不碰知识域表、列或触发器,因此 v091
|
||||
// 由 v090 克隆后只改版本字段,不复制一份表/列/触发器常量。
|
||||
const V091Version = 137
|
||||
|
||||
// RelatedTableClass 是知识域关联表的搬运归类。copied = 随整库搬运(即该版本的
|
||||
// Required/Optional 表);derived = 由触发器/应用派生,不单独搬运;excluded =
|
||||
// 明确不搬,必须写明原因。分类只写在 profile 这一处,门禁按它放行。
|
||||
type RelatedTableClass string
|
||||
|
||||
const (
|
||||
RelatedCopied RelatedTableClass = "copied"
|
||||
RelatedDerived RelatedTableClass = "derived"
|
||||
RelatedExcluded RelatedTableClass = "excluded"
|
||||
)
|
||||
|
||||
type RelatedTable struct {
|
||||
Class RelatedTableClass
|
||||
Reason string
|
||||
}
|
||||
|
||||
// PartRequirement 是归档部件的一项要求(kind/name 与 manifest 的部件键一致)。
|
||||
type PartRequirement struct {
|
||||
Kind string
|
||||
@@ -41,6 +62,9 @@ type Profile struct {
|
||||
ReviewedTriggers []string
|
||||
RequiredParts []PartRequirement
|
||||
OptionalParts []PartRequirement
|
||||
// RelatedTables 是该版本全部知识域关联表的归类(copied/derived/excluded)。
|
||||
// 漏表门禁按它判定:未归类且有本库数据的表一律拒绝。
|
||||
RelatedTables map[string]RelatedTable
|
||||
// IndexContractSource 说明该版本的索引名从哪里读。空值等于"读不到",
|
||||
// 不允许回退成空串去匹配任何索引。
|
||||
IndexContractSource string
|
||||
@@ -93,6 +117,9 @@ var profiles = map[int]Profile{
|
||||
"knowledges", "chunks", "knowledge_tags", "knowledge_tag_relations",
|
||||
"resources", "resource_bindings", "wiki_folders", "wiki_pages",
|
||||
"wiki_page_issues",
|
||||
// 编辑历史随内容搬运(D1)。放在父表之后:importRows 按本序插入、
|
||||
// 倒序删除,两张历史表因此在 chunks/wiki_pages 之后写、在它们之前删。
|
||||
"chunk_revisions", "wiki_page_revisions",
|
||||
},
|
||||
// 0.9.0 删掉了 wiki_log_entries;部件集合随之为空,不许假装还有。
|
||||
OptionalTables: []string{"wiki_log_entries"},
|
||||
@@ -106,12 +133,15 @@ var profiles = map[int]Profile{
|
||||
"wiki_pages": {"id", "tenant_id", "knowledge_base_id", "slug"},
|
||||
"wiki_folders": {"id", "tenant_id", "knowledge_base_id"},
|
||||
"wiki_page_issues": {"id", "tenant_id", "knowledge_base_id"},
|
||||
"chunk_revisions": {"id", "tenant_id", "knowledge_base_id", "knowledge_id", "chunk_id"},
|
||||
"wiki_page_revisions": {"id", "tenant_id", "knowledge_base_id", "page_id"},
|
||||
},
|
||||
RequiredParts: []PartRequirement{
|
||||
{"database", "knowledges"}, {"database", "chunks"},
|
||||
{"database", "knowledge_tags"}, {"database", "knowledge_tag_relations"},
|
||||
{"database", "resources"}, {"database", "resource_bindings"},
|
||||
{"wiki", "wiki_folders"}, {"wiki", "wiki_pages"}, {"wiki", "wiki_page_issues"},
|
||||
{"database", "chunk_revisions"}, {"wiki", "wiki_page_revisions"},
|
||||
{"index", "chunks"},
|
||||
},
|
||||
OptionalParts: []PartRequirement{
|
||||
@@ -130,19 +160,74 @@ var profiles = map[int]Profile{
|
||||
},
|
||||
}
|
||||
|
||||
// init 在一次声明上补齐两件事,避免复制常量:
|
||||
// 1. 每个版本的知识域关联表分类(copied 由该版本的 Required/Optional 表派生);
|
||||
// 2. v0.9.1 = v0.9.0 的克隆,只改版本字段。135–137 不碰知识域,表/列/触发器/
|
||||
// 部件必须与 v090 完全一致,任何分叉都会被测试抓住。
|
||||
func init() {
|
||||
for version, profile := range profiles {
|
||||
profile.RelatedTables = classifyKnowledgeTables(profile)
|
||||
profiles[version] = profile
|
||||
}
|
||||
v090 := profiles[V090Version]
|
||||
v091 := v090
|
||||
v091.Name, v091.SchemaVersion, v091.WeKnoraVersion = "v091", V091Version, "v0.9.1"
|
||||
profiles[V091Version] = v091
|
||||
}
|
||||
|
||||
// classifyKnowledgeTables 把该版本声明过的表标成 copied,并补上派生/排除表。
|
||||
// 分类键覆盖真实 0.9.x 中所有带 knowledge_base_id/knowledge_id/kb_id 的表:
|
||||
// 漏一张,漏表门禁就会在该表有数据时拒绝发布。
|
||||
func classifyKnowledgeTables(profile Profile) map[string]RelatedTable {
|
||||
tables := make(map[string]RelatedTable, len(profile.RequiredTables)+len(profile.OptionalTables)+len(excludedKnowledgeTables)+1)
|
||||
for name, reason := range excludedKnowledgeTables {
|
||||
tables[name] = RelatedTable{Class: RelatedExcluded, Reason: reason}
|
||||
}
|
||||
// 派生表:由触发器维护,随父表重算;不单独搬运。
|
||||
tables["chunk_images"] = RelatedTable{Class: RelatedDerived,
|
||||
Reason: "chunks 上的 chunk_images_sync 触发器维护的图片投影表,随 chunks 重算"}
|
||||
for _, name := range profile.RequiredTables {
|
||||
tables[name] = RelatedTable{Class: RelatedCopied, Reason: "知识库内容表,随整库搬运并做范围改写与目标身份映射"}
|
||||
}
|
||||
for _, name := range profile.OptionalTables {
|
||||
tables[name] = RelatedTable{Class: RelatedCopied, Reason: "知识库内容表(可选),存在时随整库搬运并做范围改写与目标身份映射"}
|
||||
}
|
||||
return tables
|
||||
}
|
||||
|
||||
// excludedKnowledgeTables 是明确不搬的知识域关联表及原因。原因必须解释
|
||||
// "为什么生产不需要它/为什么覆盖会破坏目标",不能只写"不搬"。
|
||||
var excludedKnowledgeTables = map[string]string{
|
||||
"knowledge_processing_spans": "解析流水线的阶段遥测;生产只做推理、不解析,搬运会把测试侧处理过程当成生产内容",
|
||||
"sessions": "对话会话属于各环境自己的运行数据,搬运会覆盖/污染目标用户会话",
|
||||
"messages": "对话消息属于各环境自己的运行数据,不能从测试库覆盖生产",
|
||||
"memory_doc_affinity": "记忆与文档的运行期关联,生产会自行建立,搬运会造成跨环境语义错配",
|
||||
"user_kb_pins": "用户置顶是各环境自己的偏好配置,生产用户 ID 在测试侧不存在",
|
||||
"kb_shares": "组织共享关系绑定本实例的组织/用户,跨环境搬运会产生无效授权",
|
||||
"im_channels": "IM 渠道配置属于各环境的接入配置,含环境专属凭据/回调",
|
||||
"data_sources": "数据源配置属于各环境的接入配置,生产不复用测试侧连接",
|
||||
"embeddings": "仅 PG 检索模式(条件迁移)创建的向量表;本平台契约固定 elasticsearch_v8,检索不读它",
|
||||
}
|
||||
|
||||
// RelatedTableClass 返回某张关联表的分类与理由;未分类时 ok=false。
|
||||
func (p Profile) RelatedTableClass(name string) (RelatedTable, bool) {
|
||||
table, ok := p.RelatedTables[name]
|
||||
return table, ok
|
||||
}
|
||||
|
||||
// For 按版本号选中 profile。未知版本一律失败:版本号是"选哪份声明"的索引,
|
||||
// 不是"能不能放行"的依据,所以绝不返回默认 profile。
|
||||
func For(version int) (Profile, error) {
|
||||
profile, ok := profiles[version]
|
||||
if !ok {
|
||||
return Profile{}, fmt.Errorf("unsupported WeKnora schema version %d: supported profiles are 74 (v071) and 134 (v090)", version)
|
||||
return Profile{}, fmt.Errorf("unsupported WeKnora schema version %d: supported profiles are 74 (v071), 134 (v090) and 137 (v091)", version)
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
// Supported 返回已声明 profile 的版本号(用于文档与错误信息,不用于放行)。
|
||||
func Supported() []int {
|
||||
return []int{LegacyVersion, V090Version}
|
||||
return []int{LegacyVersion, V090Version, V091Version}
|
||||
}
|
||||
|
||||
// TableSet 是"可能出现的表"集合:必需表 + 可选表。
|
||||
|
||||
Reference in New Issue
Block a user