WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s

This commit is contained in:
yawan
2026-09-22 16:19:06 +08:00
commit f7fc992f57
3929 changed files with 1006607 additions and 0 deletions
+101
View File
@@ -0,0 +1,101 @@
package knowledgeversion
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"time"
"github.com/Tencent/WeKnora/internal/types"
"gorm.io/gorm"
)
// GraphRecord retains original evidence IDs and payloads in each independent KB.
type GraphRecord struct {
TenantID uint64 `gorm:"primaryKey"`
KnowledgeBaseID string `gorm:"primaryKey"`
SourceTable string `gorm:"primaryKey"`
LegacyID int64 `gorm:"primaryKey;autoIncrement:false"`
GraphVersionID int64
Payload types.JSON `gorm:"type:jsonb"`
SourceSnapshotSHA256 string `gorm:"column:source_snapshot_sha256"`
ImportedAt time.Time
}
func (GraphRecord) TableName() string { return "native_graph_records" }
type GraphSource struct {
TenantID uint64 `gorm:"primaryKey"`
KnowledgeBaseID string `gorm:"primaryKey"`
SourceChunkID string `gorm:"primaryKey"`
SourceFile string
SourceContentHash string
Excerpt string
NativeKnowledgeID *string
NativeChunkID *string
NativeContentSHA256 *string `gorm:"column:native_content_sha256"`
MappingState string
}
func (GraphSource) TableName() string { return "native_graph_sources" }
func GraphTablesExist(db *gorm.DB) bool {
return db.Migrator().HasTable(&GraphRecord{}) && db.Migrator().HasTable(&GraphSource{})
}
// GraphFingerprint participates in approval conflict detection without exposing
// source paths, legacy payloads or private document identifiers to reviewers.
func GraphFingerprint(db *gorm.DB, tenant uint64, kb string) (string, error) {
if !GraphTablesExist(db) {
return "", nil
}
h := sha256.New()
count := 0
for _, item := range []struct {
model any
order string
}{
{&GraphRecord{}, "source_table, legacy_id"}, {&GraphSource{}, "source_chunk_id"},
} {
rows, err := db.Model(item.model).Where("tenant_id=? AND knowledge_base_id=?", tenant, kb).Order(item.order).Rows()
if err != nil {
return "", err
}
for rows.Next() {
var value any = &GraphRecord{}
if _, ok := item.model.(*GraphSource); ok {
value = &GraphSource{}
}
if err := db.ScanRows(rows, value); err != nil {
rows.Close()
return "", err
}
if err := json.NewEncoder(h).Encode(value); err != nil {
rows.Close()
return "", err
}
count++
}
err = rows.Err()
rows.Close()
if err != nil {
return "", err
}
}
if count == 0 {
return "", nil
}
return hex.EncodeToString(h.Sum(nil)), nil
}
func DeleteGraph(db *gorm.DB, tenant uint64, kb string) error {
if !GraphTablesExist(db) {
return nil
}
for _, model := range []any{&GraphSource{}, &GraphRecord{}} {
if err := db.Where("tenant_id=? AND knowledge_base_id=?", tenant, kb).Delete(model).Error; err != nil {
return err
}
}
return nil
}