MCPcopy Create free account
hub / github.com/dolthub/doltgresql / createDefaultDatabase

Function createDefaultDatabase

server/server.go:200–216  ·  view source on GitHub ↗

createDefaultDatabase creates the database named on the local server using the configuration values to connect, returning any error

(cfg doltservercfg.ServerConfig)

Source from the content-addressed store, hash-verified

198// createDefaultDatabase creates the database named on the local server using the configuration values to connect, returning
199// any error
200func createDefaultDatabase(cfg doltservercfg.ServerConfig) error {
201 user, password := auth.GetSuperUserAndPassword()
202 dbName := getDefaultDatabaseName(user)
203
204 dsn := fmt.Sprintf("postgres://%s:%s@localhost:%d", user, password, cfg.Port())
205
206 // Connect to the server and create the default database with the given name.
207 ctx := context.Background()
208 conn, err := pgx.Connect(ctx, dsn)
209 if err != nil {
210 return err
211 }
212 defer conn.Close(ctx)
213
214 _, err = conn.Exec(ctx, fmt.Sprintf("CREATE DATABASE %s;", dbName))
215 return err
216}
217
218// getDefaultDatabaseName returns the name of the default database to create on first server start.
219// If the environment variable DOLTGRES_DB is set, that value is used. Otherwise, the username is used.

Callers 1

runServerFunction · 0.85

Calls 6

GetSuperUserAndPasswordFunction · 0.92
getDefaultDatabaseNameFunction · 0.85
PortMethod · 0.80
ConnectMethod · 0.80
ExecMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected