fix: Z35 禁止用中文昵称作 Postgres 库名,发布时纠正脏数据
绑定 database_name 改为 user_{id};publish 遇非法库名 Sanitize 并回写,避免 EnsureDatabase 400。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -90,3 +90,21 @@ func SanitizeDBName(tenantID int64, slug string) string {
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// ValidDBName 是否可作为 Postgres 物理库名(CREATE DATABASE)。
|
||||
func ValidDBName(dbName string) bool {
|
||||
return dbNameRe.MatchString(strings.TrimSpace(dbName))
|
||||
}
|
||||
|
||||
// SafePhysicalDBName 优先用 preferred;非法则用 fallback;仍非法则 user_fallback。
|
||||
func SafePhysicalDBName(preferred, fallback string) string {
|
||||
p := strings.TrimSpace(preferred)
|
||||
if ValidDBName(p) {
|
||||
return p
|
||||
}
|
||||
f := strings.TrimSpace(fallback)
|
||||
if ValidDBName(f) {
|
||||
return f
|
||||
}
|
||||
return "appdb_default"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user