createDefaultDatabase creates the database named on the local server using the configuration values to connect, returning any error
(cfg doltservercfg.ServerConfig)
| 198 | // createDefaultDatabase creates the database named on the local server using the configuration values to connect, returning |
| 199 | // any error |
| 200 | func 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. |
no test coverage detected