dcdc8d1ddd
全栈知识治理平台首次入库(P1-P10 + 发布链路模拟验证闭环): - 治理核心:源目录/变更集/人工审核/发布批次/发布执行(fail-closed 闸口) - 测试通道:WeKnora 测试 KB 上传/轮询/验收;poll 完成时写入 parser_generation/index_generation,修复 manual/seed 路径发布闸口永久拦截 - 发布适配器 v071(本地 source=测试角色 / 云端 target=生产角色 模拟验证通过): * ES 导出/导入 mapping 自适应(.keyword 子字段、可选 tenant_id) * OSS locator 支持嵌套 scheme;chunks.seq_id 由目标序列分配 * bundle 归档同身份重试原子替换;verifier 按 bundle chunk_type 计数 * 回滚 job payload 支持 prior_execution_id(strict 解码) - 三通道发布+回滚演练实测:publish 4/4 verified,检索命中, rollback 4/4 rolled_back,目标端 PG is_enabled=false、ES is_enabled=false - 前端 A·Data-console 风格全站统一,120 用例通过 - 门禁:go vet / go test 全包通过,gofmt 干净
164 lines
7.2 KiB
Go
164 lines
7.2 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
|
|
"knowledge-governance/internal/governance"
|
|
)
|
|
|
|
func runOperation[T any](s *Store, ctx context.Context, operationType, operationID, fingerprint string, now time.Time, execute func(pgx.Tx) (T, error)) (T, bool, error) {
|
|
var zero T
|
|
raw, replayed, err := s.executeOperation(ctx, operationType, operationID, fingerprint, now, func(tx pgx.Tx) (json.RawMessage, error) {
|
|
result, err := execute(tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(result)
|
|
})
|
|
if err != nil {
|
|
return zero, false, err
|
|
}
|
|
var result T
|
|
if err := json.Unmarshal(raw, &result); err != nil {
|
|
return zero, false, err
|
|
}
|
|
return result, replayed, nil
|
|
}
|
|
|
|
func (s *Store) TriggerPPSourceScanWithOperation(ctx context.Context, connectionID string, now time.Time, operationID string) (governance.SourceScan, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
ConnectionID string `json:"connection_id"`
|
|
}{connectionID})
|
|
if err != nil {
|
|
return governance.SourceScan{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "source.scan.trigger", operationID, fingerprint, now, func(tx pgx.Tx) (governance.SourceScan, error) {
|
|
return NewStore(tx).TriggerPPSourceScan(ctx, connectionID, now)
|
|
})
|
|
}
|
|
|
|
func (s *Store) CreateUISettingsCandidateWithOperation(ctx context.Context, request governance.CreateUISettingsCandidateRequest, operationID string) (governance.UISettings, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
Document int `json:"document_refresh_seconds"`
|
|
Resource int `json:"resource_refresh_seconds"`
|
|
Stalled int `json:"stalled_after_seconds"`
|
|
Finalize int `json:"finalizing_after_seconds"`
|
|
By string `json:"updated_by"`
|
|
}{request.DocumentRefreshSeconds, request.ResourceRefreshSeconds, request.StalledAfterSeconds, request.FinalizingAfterSeconds, request.UpdatedBy})
|
|
if err != nil {
|
|
return governance.UISettings{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "ui_settings.candidate.create", operationID, fingerprint, request.Now.UTC(), func(tx pgx.Tx) (governance.UISettings, error) {
|
|
return NewStore(tx).CreateUISettingsCandidate(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) ActivateUISettingsWithOperation(ctx context.Context, revisionID string, now time.Time, operationID string) (governance.UISettings, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
RevisionID string `json:"revision_id"`
|
|
}{revisionID})
|
|
if err != nil {
|
|
return governance.UISettings{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "ui_settings.activate", operationID, fingerprint, now.UTC(), func(tx pgx.Tx) (governance.UISettings, error) {
|
|
return NewStore(tx).ActivateUISettings(ctx, revisionID, now)
|
|
})
|
|
}
|
|
|
|
func (s *Store) CreateReleaseBatchWithOperation(ctx context.Context, request governance.CreateReleaseBatchRequest, operationID string) (governance.ReleaseBatch, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
Name string `json:"name"`
|
|
By string `json:"created_by"`
|
|
Upsert []string `json:"publication_ids"`
|
|
Delete []string `json:"delete_publication_ids"`
|
|
Set string `json:"release_change_set_id"`
|
|
}{request.Name, request.CreatedBy, request.PublicationIDs, request.DeletePublicationIDs, request.ReleaseChangeSetID})
|
|
if err != nil {
|
|
return governance.ReleaseBatch{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.batch.create", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseBatch, error) {
|
|
return NewStore(tx).CreateReleaseBatch(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) GenerateReleaseChangeSetWithOperation(ctx context.Context, request governance.GenerateReleaseChangeSetRequest, operationID string) (governance.ReleaseChangeSet, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
Name string `json:"name"`
|
|
By string `json:"created_by"`
|
|
}{request.Name, request.CreatedBy})
|
|
if err != nil {
|
|
return governance.ReleaseChangeSet{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.changeset.generate", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseChangeSet, error) {
|
|
return NewStore(tx).GenerateReleaseChangeSet(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) ConfirmReleaseChangeSetWithOperation(ctx context.Context, request governance.ConfirmReleaseChangeSetRequest, operationID string) (governance.ReleaseChangeSet, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
ID string `json:"change_set_id"`
|
|
By string `json:"confirmed_by"`
|
|
}{request.ChangeSetID, request.ConfirmedBy})
|
|
if err != nil {
|
|
return governance.ReleaseChangeSet{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.changeset.confirm", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseChangeSet, error) {
|
|
return NewStore(tx).ConfirmReleaseChangeSet(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) SealReleaseBatchWithOperation(ctx context.Context, request governance.SealReleaseBatchRequest, operationID string) (governance.ReleaseBatch, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
BatchID string `json:"batch_id"`
|
|
SealedBy string `json:"sealed_by"`
|
|
}{request.BatchID, request.SealedBy})
|
|
if err != nil {
|
|
return governance.ReleaseBatch{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.batch.seal", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseBatch, error) {
|
|
return NewStore(tx).SealReleaseBatch(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) AuthorizeReleaseBatchWithOperation(ctx context.Context, request governance.AuthorizeReleaseBatchRequest, operationID string) (governance.ReleaseExecution, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
BatchID string `json:"batch_id"`
|
|
AuthorizedBy string `json:"authorized_by"`
|
|
}{request.BatchID, request.AuthorizedBy})
|
|
if err != nil {
|
|
return governance.ReleaseExecution{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.authorize.publish", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseExecution, error) {
|
|
return NewStore(tx).AuthorizeReleaseBatch(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) AuthorizeReleaseRollbackWithOperation(ctx context.Context, request governance.AuthorizeReleaseRollbackRequest, operationID string) (governance.ReleaseExecution, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
PriorID string `json:"prior_execution_id"`
|
|
AuthorizedBy string `json:"authorized_by"`
|
|
}{request.PriorExecutionID, request.AuthorizedBy})
|
|
if err != nil {
|
|
return governance.ReleaseExecution{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.authorize.rollback", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseExecution, error) {
|
|
return NewStore(tx).AuthorizeReleaseRollback(ctx, request)
|
|
})
|
|
}
|
|
|
|
func (s *Store) RetryReleaseExecutionWithOperation(ctx context.Context, request governance.RetryReleaseExecutionRequest, operationID string) (governance.ReleaseExecution, bool, error) {
|
|
fingerprint, err := operationFingerprint(struct {
|
|
ExecutionID string `json:"execution_id"`
|
|
}{request.ExecutionID})
|
|
if err != nil {
|
|
return governance.ReleaseExecution{}, false, err
|
|
}
|
|
return runOperation(s, ctx, "release.execution.retry", operationID, fingerprint, request.Now, func(tx pgx.Tx) (governance.ReleaseExecution, error) {
|
|
return NewStore(tx).RetryReleaseExecution(ctx, request)
|
|
})
|
|
}
|