-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting doltgres server creates db in defined data directory (#83)
- Loading branch information
1 parent
d38f316
commit a444d36
Showing
5 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ const ( | |
DOLTGRES_DATA_DIR = "DOLTGRES_DATA_DIR" | ||
// DOLTGRES_DATA_DIR_DEFAULT is the portion to append to the user's home directory if DOLTGRES_DATA_DIR has not been specified | ||
DOLTGRES_DATA_DIR_DEFAULT = "doltgres/databases" | ||
|
||
DefUserName = "postres" | ||
DefUserEmail = "[email protected]" | ||
DoltgresDir = "doltgres" | ||
) | ||
|
||
var sqlServerDocs = cli.CommandDocumentationContent{ | ||
|
@@ -134,8 +138,8 @@ func RunInMemory(args []string) (*svcs.Controller, error) { | |
globalConfig, _ := dEnv.Config.GetConfig(env.GlobalConfig) | ||
if globalConfig.GetStringOrDefault(config.UserNameKey, "") == "" { | ||
globalConfig.SetStrings(map[string]string{ | ||
config.UserNameKey: "postgres", | ||
config.UserEmailKey: "[email protected]", | ||
config.UserNameKey: DefUserName, | ||
config.UserEmailKey: DefUserEmail, | ||
}) | ||
} | ||
|
||
|
@@ -188,26 +192,29 @@ func runServer(ctx context.Context, args []string, dEnv *env.DoltEnv) (*svcs.Con | |
|
||
// We need a username and password for many SQL commands, so set defaults if they don't exist | ||
dEnv.Config.SetFailsafes(map[string]string{ | ||
config.UserNameKey: "postgres", | ||
config.UserEmailKey: "[email protected]", | ||
config.UserNameKey: DefUserName, | ||
config.UserEmailKey: DefUserEmail, | ||
}) | ||
|
||
// Automatically initialize a doltgres database if necessary | ||
if !dEnv.HasDoltDir() { | ||
// Need to make sure that there isn't a doltgres item in the path. | ||
if exists, isDirectory := dEnv.FS.Exists("doltgres"); !exists { | ||
err := dEnv.FS.MkDirs("doltgres") | ||
if exists, isDirectory := dEnv.FS.Exists(DoltgresDir); !exists { | ||
err := dEnv.FS.MkDirs(DoltgresDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
subdirectoryFS, err := dEnv.FS.WithWorkingDir("doltgres") | ||
subdirectoryFS, err := dEnv.FS.WithWorkingDir(DoltgresDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// We'll use a temporary environment to instantiate the subdirectory | ||
tempDEnv := env.Load(ctx, env.GetCurrentUserHomeDir, subdirectoryFS, dEnv.UrlStr(), Version) | ||
res := commands.InitCmd{}.Exec(ctx, "init", []string{}, tempDEnv, configCliContext{tempDEnv}) | ||
// username and user email is needed to create a new database. | ||
name := tempDEnv.Config.GetStringOrDefault(config.UserNameKey, DefUserName) | ||
email := tempDEnv.Config.GetStringOrDefault(config.UserEmailKey, DefUserEmail) | ||
res := commands.InitCmd{}.Exec(ctx, "init", []string{"--name", name, "--email", email}, tempDEnv, configCliContext{tempDEnv}) | ||
if res != 0 { | ||
return nil, fmt.Errorf("failed to initialize doltgres database") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env bats | ||
load $BATS_TEST_DIRNAME/setup/common.bash | ||
|
||
setup() { | ||
setup_common | ||
# tests are run without setting doltgres config user.name and user.email | ||
stash_current_dolt_user | ||
unset_dolt_user | ||
} | ||
|
||
teardown() { | ||
restore_stashed_dolt_user | ||
teardown_common | ||
} | ||
|
||
@test 'doltgres: DOLTGRES_DATA_DIR set to current dir' { | ||
[ ! -d "doltgres" ] | ||
export DOLTGRES_DATA_DIR="$(pwd)" | ||
export SQL_USER="doltgres" | ||
start_sql_server_with_args "--host 0.0.0.0" "--user doltgres" > log.txt 2>&1 | ||
|
||
run cat log.txt | ||
[[ ! "$output" =~ "Author identity unknown" ]] || false | ||
[ -d "doltgres" ] | ||
|
||
run query_server -c "\l" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "information_schema" ]] || false | ||
[[ "$output" =~ "doltgres" ]] || false | ||
[[ "$output" =~ "postgres" ]] || false | ||
} | ||
|
||
@test 'doltgres: setting both --data-dir and DOLTGRES_DATA_DIR should use --data-dir value' { | ||
[ ! -d "doltgres" ] | ||
|
||
export DOLTGRES_DATA_DIR="$(pwd)" | ||
export SQL_USER="doltgres" | ||
start_sql_server_with_args "--host 0.0.0.0" "--user doltgres" "--data-dir=./test" > log.txt 2>&1 | ||
|
||
run cat log.txt | ||
[[ ! "$output" =~ "Author identity unknown" ]] || false | ||
[ ! -d "doltgres" ] | ||
[ -d "test/doltgres" ] | ||
|
||
run query_server -c "\l" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "information_schema" ]] || false | ||
[[ "$output" =~ "doltgres" ]] || false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters