ecf518e3bb
build / build (push) Successful in 2m5s
- OpenBaselineStack 用目标库解析出的 profile 校验 schema(134 合法), contract.WeKnoraVersion 取 profile 值 - no-gate 维护参数(IngressMode/IngressAck/HealthURL)从配置透传, 否则 0.9.0 目标会被当成缺闸门拒绝 - 索引写入与校验按 profile 决定是否补 tenant_id(0.9.0 索引无该字段)
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, scopeWhereFor(profile.Tables, 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
|
|
}
|