fba2713b4e
build / build (push) Successful in 1m54s
整库发布写入路径原先按 0.7.1 的固定表集合工作:0.9.0 没有 wiki_log_entries, Current/清理/编目/整实例指纹都会在不存在表上失败,跨版本闸门也因快照丢掉 SchemaVersion 而失效(未知版本被当作 74)。 改为在装配时解析目标 profile,表集合与清理顺序按解析结果;快照复制与范围改写 带上 SchemaVersion/Profile;跨版本发布显式拒绝并同时点名两个版本。单文档发布包 仍只支持 0.7.1,但改为明确拒绝并说明原因。 本机隔离验证:真实 0.9.0 schema 源库→导出→封存→写入干净 134 目标→逐表核对→ 写前镜像回滚;74→134 拒绝与 134 缺表不报错两个负例通过。make verify 17 项全绿。
51 lines
1.9 KiB
Go
51 lines
1.9 KiB
Go
package v071
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// ScopeContentCounts 数一个知识库在各内容表里的行数(数据库侧事实)。
|
|
//
|
|
// 为什么不能只数 knowledges:文档被删掉、分块与 Wiki/资源还在的库并不为空。
|
|
// 只数一张表会把这种目标判成"首次发布的空库",从而让一条本该走基线初始化的
|
|
// 路径绕过去;这里用与整库读写完全相同的表清单与过滤条件,保证"空"的定义只有一份。
|
|
func ScopeContentCounts(ctx context.Context, pool *pgxpool.Pool, identity ProductionScope) (map[string]int64, error) {
|
|
if pool == nil || identity.TenantID == 0 || !validSearchIdentifier(identity.KnowledgeBaseID) {
|
|
return nil, errors.New("invalid scope identity")
|
|
}
|
|
profile, err := ResolveSchemaProfile(ctx, pool, "scope content probe")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
counts := make(map[string]int64, len(profile.Tables))
|
|
for _, table := range profile.Tables {
|
|
var count int64
|
|
if err := pool.QueryRow(ctx, fmt.Sprintf(`SELECT count(*) FROM %s WHERE %s`, table, scopeWhere(table)),
|
|
identity.TenantID, identity.KnowledgeBaseID).Scan(&count); err != nil {
|
|
return nil, fmt.Errorf("count %s: %w", table, err)
|
|
}
|
|
counts[table] = count
|
|
}
|
|
return counts, nil
|
|
}
|
|
|
|
// ScopeContentEmpty 只有每张内容表都是 0 才算空目标,并交回逐表行数作为证据。
|
|
// 注意它**不**包含检索索引:索引由分块派生,分块为空而索引非空属于不一致,
|
|
// 应在执行侧(预备份/基线捕获)报出来,不能在这里被当成"空"。
|
|
func ScopeContentEmpty(ctx context.Context, pool *pgxpool.Pool, identity ProductionScope) (bool, map[string]int64, error) {
|
|
counts, err := ScopeContentCounts(ctx, pool, identity)
|
|
if err != nil {
|
|
return false, nil, err
|
|
}
|
|
for _, count := range counts {
|
|
if count != 0 {
|
|
return false, counts, nil
|
|
}
|
|
}
|
|
return true, counts, nil
|
|
}
|