fix: Z39 isolate module data by slug
Keep agent-bound modules in per-app schemas and prevent stale frontend routes from displaying another module's blueprint or rows. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package blueprint
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
@@ -48,12 +49,12 @@ type Storage struct {
|
||||
}
|
||||
|
||||
type Entity struct {
|
||||
Name string `json:"name"`
|
||||
Table string `json:"table"`
|
||||
Label string `json:"label"`
|
||||
PrimaryKey string `json:"primary_key"`
|
||||
Fields []Field `json:"fields"`
|
||||
Indexes []Index `json:"indexes,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Table string `json:"table"`
|
||||
Label string `json:"label"`
|
||||
PrimaryKey string `json:"primary_key"`
|
||||
Fields []Field `json:"fields"`
|
||||
Indexes []Index `json:"indexes,omitempty"`
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
@@ -271,10 +272,7 @@ func (bp *Blueprint) AssignSchemaName(tenantID int64) string {
|
||||
bp.Storage.SchemaName = "public"
|
||||
return "public"
|
||||
}
|
||||
name := fmt.Sprintf("app_t%d_%s", tenantID, bp.Meta.Slug)
|
||||
if len(name) > 48 {
|
||||
name = name[:48]
|
||||
}
|
||||
name := scopedIdent(fmt.Sprintf("app_t%d_%s", tenantID, bp.Meta.Slug))
|
||||
bp.Storage.SchemaName = name
|
||||
return name
|
||||
}
|
||||
@@ -284,11 +282,30 @@ func (bp *Blueprint) AssignDatabaseName(tenantID int64) string {
|
||||
if bp.Storage.Mode != "database_per_app" {
|
||||
return ""
|
||||
}
|
||||
name := fmt.Sprintf("appdb_t%d_%s", tenantID, bp.Meta.Slug)
|
||||
if len(name) > 48 {
|
||||
name = name[:48]
|
||||
return scopedIdent(fmt.Sprintf("appdb_t%d_%s", tenantID, bp.Meta.Slug))
|
||||
}
|
||||
|
||||
// scopedIdent 保留可读前缀,并为超长标识符附加内容哈希,避免不同 slug 截断后碰撞。
|
||||
func scopedIdent(raw string) string {
|
||||
if len(raw) <= 48 {
|
||||
return raw
|
||||
}
|
||||
return name
|
||||
sum := sha256.Sum256([]byte(raw))
|
||||
suffix := fmt.Sprintf("_%x", sum[:6])
|
||||
return raw[:48-len(suffix)] + suffix
|
||||
}
|
||||
|
||||
// Revision 返回蓝图内容的稳定短哈希,用于发布回执、缓存隔离与诊断日志。
|
||||
func (bp *Blueprint) Revision() string {
|
||||
if bp == nil {
|
||||
return ""
|
||||
}
|
||||
raw, err := json.Marshal(bp)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
sum := sha256.Sum256(raw)
|
||||
return fmt.Sprintf("%x", sum[:8])
|
||||
}
|
||||
|
||||
func checkIdent(field, v string) error {
|
||||
|
||||
Reference in New Issue
Block a user