3f2626f621
build / build (push) Failing after 1m32s
按 schema 版本选 profile 并以 information_schema 能力探测放行,取代写死的 version==74;未知版本、脏库、缺表缺列、跨版本搬运一律拒绝并点名原因。 0.9.0 的索引名改从部署配置解析,wiki_log_entries 按 profile 变为可选, 归档部件集合随之一致。
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package v071
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"errors"
|
|
)
|
|
|
|
// IndexMappingDigest 与线上读取路径(SearchExporter.inspectMapping)用同一套规范化:
|
|
// 取 ES `/{index}/_mapping` 响应里该索引的 mappings,规范 JSON 后取 sha256。
|
|
//
|
|
// 单独暴露它是为了能用**真实抓下来的映射**证明摘要可算,并证明 0.7.1 与 0.9.0
|
|
// 的映射是两个不同契约(不能因为"都是 1024 维"就当同一份)。
|
|
func IndexMappingDigest(raw []byte) (string, error) {
|
|
var response map[string]json.RawMessage
|
|
if err := json.Unmarshal(raw, &response); err != nil || len(response) != 1 {
|
|
return "", errors.New("Elasticsearch mapping response is invalid")
|
|
}
|
|
for _, indexRaw := range response {
|
|
var index struct {
|
|
Mappings json.RawMessage `json:"mappings"`
|
|
}
|
|
if err := json.Unmarshal(indexRaw, &index); err != nil || len(index.Mappings) == 0 {
|
|
return "", errors.New("Elasticsearch mapping response is invalid")
|
|
}
|
|
canonical, err := canonicalJSON(index.Mappings)
|
|
if err != nil {
|
|
return "", errors.New("Elasticsearch mapping response is invalid")
|
|
}
|
|
digest := sha256.Sum256(canonical)
|
|
return hex.EncodeToString(digest[:]), nil
|
|
}
|
|
return "", errors.New("Elasticsearch mapping response is invalid")
|
|
}
|