- 迁移 000084 保存对内/对外绑定名称快照;清除密钥后仍显示已绑定库,不再只显示裸 ID - 测试/生产换绑只重指向同一侧的旧目标,避免测试保存误改另一环境的待入库 - 已保存连接但没有可用密钥时拒绝改绑定,禁止静默回落文件 Key - 生产换绑返回重指向/退休数量,页面提示与测试侧一致 验证:make verify(含隔离 PostgreSQL 集成用例)15/15 通过
This commit is contained in:
@@ -14,10 +14,10 @@ import (
|
||||
// (migration 000034). Empty stored values fall back to env defaults.
|
||||
type RoutingBindingStore interface {
|
||||
LoadRoutingKBBindings(context.Context) (string, string, string, error)
|
||||
SaveRoutingKBBindings(context.Context, string, string, string) error
|
||||
LoadRoutingKBBindingNames(context.Context) (string, string, error)
|
||||
// SaveRoutingKBBindingsWithReplan also re-points 待入库 publications that
|
||||
// were still waiting for the previous knowledge base (same transaction).
|
||||
SaveRoutingKBBindingsWithReplan(ctx context.Context, internalID, externalID, effectiveInternal, effectiveExternal, updatedBy string, now time.Time) (postgresstore.RoutingBindingReplanResult, error)
|
||||
SaveRoutingKBBindingsWithReplan(ctx context.Context, save postgresstore.RoutingBindingSave, previous, effective postgresstore.EffectiveKBIDs, now time.Time) (postgresstore.RoutingBindingReplanResult, error)
|
||||
}
|
||||
|
||||
// KnowledgeBaseLister enumerates candidate knowledge bases in the connected
|
||||
@@ -97,14 +97,33 @@ func (config Config) routingBindingPayload(ctx context.Context, replan postgress
|
||||
if err != nil {
|
||||
return routingBindingView{}, err
|
||||
}
|
||||
internal, external := config.effectiveRoutingTargets(ctx)
|
||||
storedInternalName, storedExternalName, err := config.RoutingBindings.LoadRoutingKBBindingNames(ctx)
|
||||
if err != nil {
|
||||
return routingBindingView{}, err
|
||||
}
|
||||
internal, external := storedInternal, storedExternal
|
||||
if internal == "" {
|
||||
internal = config.InternalRoutingKnowledgeBaseID
|
||||
}
|
||||
if external == "" {
|
||||
external = config.ExternalRoutingKnowledgeBaseID
|
||||
}
|
||||
nameFor := func(id, storedName string) string {
|
||||
if id == "" {
|
||||
return ""
|
||||
}
|
||||
if connected {
|
||||
return names[id]
|
||||
}
|
||||
return storedName
|
||||
}
|
||||
return routingBindingView{
|
||||
InternalKBID: internal, ExternalKBID: external,
|
||||
InternalBoundByUI: storedInternal != "", ExternalBoundByUI: storedExternal != "",
|
||||
InternalEnvFallback: storedInternal == "" && config.InternalRoutingKnowledgeBaseID != "",
|
||||
ExternalEnvFallback: storedExternal == "" && config.ExternalRoutingKnowledgeBaseID != "",
|
||||
InternalFallbackKBID: config.InternalRoutingKnowledgeBaseID, ExternalFallbackKBID: config.ExternalRoutingKnowledgeBaseID,
|
||||
InternalKBName: names[storedInternal], ExternalKBName: names[storedExternal],
|
||||
InternalKBName: nameFor(internal, storedInternalName), ExternalKBName: nameFor(external, storedExternalName),
|
||||
UpdatedBy: updatedBy, WeKnoraConnected: connected,
|
||||
Replanned: replan.Replanned, RetiredDuplicates: replan.RetiredDuplicates,
|
||||
}, nil
|
||||
@@ -161,6 +180,10 @@ func (config Config) handleSaveRoutingBindings(w http.ResponseWriter, r *http.Re
|
||||
// offline saves fall through to the DB so the page never hard-fails, but
|
||||
// the response reports connected=false honestly.
|
||||
names, connected := config.routingBindingNames(r.Context())
|
||||
if !connected && config.connectionKeyUnusable(r.Context(), "test") {
|
||||
writeJSON(w, http.StatusConflict, map[string]string{"error": "测试 WeKnora 已保存连接但没有可用密钥:请重新录入 API Key 并测通后再改绑定"})
|
||||
return
|
||||
}
|
||||
if connected {
|
||||
if internal != "" {
|
||||
if _, ok := names[internal]; !ok {
|
||||
@@ -186,7 +209,14 @@ func (config Config) handleSaveRoutingBindings(w http.ResponseWriter, r *http.Re
|
||||
if effectiveExternal == "" {
|
||||
effectiveExternal = config.ExternalRoutingKnowledgeBaseID
|
||||
}
|
||||
replan, err := config.RoutingBindings.SaveRoutingKBBindingsWithReplan(r.Context(), internal, external, effectiveInternal, effectiveExternal, actorFor(r), config.Now().UTC())
|
||||
previousInternal, previousExternal := config.effectiveRoutingTargets(r.Context())
|
||||
replan, err := config.RoutingBindings.SaveRoutingKBBindingsWithReplan(r.Context(), postgresstore.RoutingBindingSave{
|
||||
InternalID: internal, ExternalID: external,
|
||||
InternalName: names[internal], ExternalName: names[external],
|
||||
UpdatedBy: actorFor(r),
|
||||
}, postgresstore.EffectiveKBIDs{Internal: previousInternal, External: previousExternal},
|
||||
postgresstore.EffectiveKBIDs{Internal: effectiveInternal, External: effectiveExternal},
|
||||
config.Now().UTC())
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "could not save routing bindings"})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user