增加短信渠道

This commit is contained in:
Yvan
2026-09-29 18:15:35 +08:00
parent a16b8f8e89
commit 89cc7761b5
38 changed files with 1469 additions and 39 deletions
+16 -8
View File
@@ -179,6 +179,21 @@ func openWithDriverConfig(driver, dsn string, config *config.Database, appLogger
return db, nil
}
func bootstrapDatabaseDSN(c *config.Database) (string, error) {
bootstrap := *c
// An empty name passed to databaseDSN falls back to the configured name.
// Clear both fields so MySQL can connect before the target database exists.
bootstrap.Name = ""
bootstrap.Source = ""
switch normalizedDriver(c.Driver) {
case "pgsql":
bootstrap.Name = "postgres"
case "mssql":
bootstrap.Name = "master"
}
return databaseDSN(&bootstrap, "")
}
func openDatabase(c *config.Database, create bool, template string, appLogger *slog.Logger) (*gorm.DB, error) {
driver := normalizedDriver(c.Driver)
if driver == "" {
@@ -198,14 +213,7 @@ func openDatabase(c *config.Database, create bool, template string, appLogger *s
if !databaseNamePattern.MatchString(c.Name) {
return nil, fmt.Errorf("invalid database name %q", c.Name)
}
bootstrap := ""
switch driver {
case "pgsql":
bootstrap = "postgres"
case "mssql":
bootstrap = "master"
}
dsn, err := databaseDSN(c, bootstrap)
dsn, err := bootstrapDatabaseDSN(c)
if err != nil {
return nil, err
}