增加短信渠道
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user