🎨 精简完善系统

This commit is contained in:
2026-04-10 17:57:48 +08:00
parent ee6565371e
commit 82c5020e71
55 changed files with 5785 additions and 9712 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"git.echol.cn/loser/Go-Web-Template/server/config"
"github.com/gookit/color"
@@ -19,6 +20,10 @@ import (
type PgsqlInitHandler struct{}
func quotePgIdentifier(name string) string {
return `"` + strings.ReplaceAll(name, `"`, `""`) + `"`
}
func NewPgsqlInitHandler() *PgsqlInitHandler {
return &PgsqlInitHandler{}
}
@@ -55,9 +60,13 @@ func (h PgsqlInitHandler) EnsureDB(ctx context.Context, conf *request.InitDB) (n
dsn := conf.PgsqlEmptyDsn()
var createSql string
if conf.Template != "" {
createSql = fmt.Sprintf("CREATE DATABASE %s WITH TEMPLATE %s;", c.Dbname, conf.Template)
createSql = fmt.Sprintf(
"CREATE DATABASE %s WITH TEMPLATE %s;",
quotePgIdentifier(c.Dbname),
quotePgIdentifier(conf.Template),
)
} else {
createSql = fmt.Sprintf("CREATE DATABASE %s;", c.Dbname)
createSql = fmt.Sprintf("CREATE DATABASE %s;", quotePgIdentifier(c.Dbname))
}
if err = createDatabase(dsn, "pgx", createSql); err != nil {
return nil, err