-
-
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 empty dir
- Loading branch information
1 parent
d38f316
commit 561f19e
Showing
5 changed files
with
75 additions
and
11 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 for creating a database. | ||
name := dEnv.Config.GetStringOrDefault(config.UserNameKey, DefUserName) | ||
email := dEnv.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,58 @@ | ||
#!/usr/bin/env bats | ||
load $BATS_TEST_DIRNAME/setup/common.bash | ||
|
||
setup() { | ||
setup_common | ||
} | ||
|
||
teardown() { | ||
teardown_common | ||
} | ||
|
||
@test 'doltgres: no args' { | ||
start_sql_server_with_args "--host 0.0.0.0" | ||
run query_server -c "\l" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "information_schema" ]] || false | ||
[[ "$output" =~ "doltgres" ]] || false | ||
[[ "$output" =~ "postgres" ]] || false | ||
|
||
[ ! -d "doltgres" ] | ||
} | ||
|
||
@test 'doltgres: with --data-dir' { | ||
start_sql_server_with_args "--host 0.0.0.0 --data-dir=." | ||
run query_server -c "\l" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "information_schema" ]] || false | ||
[[ "$output" =~ "doltgres" ]] || false | ||
[[ "$output" =~ "postgres" ]] || false | ||
|
||
[ -d "doltgres" ] | ||
} | ||
|
||
@test 'doltgres: with DOLTGRES_DATA_DIR' { | ||
DOLTGRES_DATA_DIR="$BATS_TEST_DIRNAME/test" | ||
start_sql_server_with_args "--host 0.0.0.0" | ||
run query_server -c "\l" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "information_schema" ]] || false | ||
[[ "$output" =~ "doltgres" ]] || false | ||
[[ "$output" =~ "postgres" ]] || false | ||
|
||
[ -d "test/doltgres" ] | ||
[ ! -d "doltgres" ] | ||
} | ||
|
||
@test 'doltgres: with both --data-dir and DOLTGRES_DATA_DIR' { | ||
DOLTGRES_DATA_DIR="$BATS_TEST_DIRNAME/test1" | ||
start_sql_server_with_args "--host 0.0.0.0 --data-dir=./test2" | ||
run query_server -c "\l" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "information_schema" ]] || false | ||
[[ "$output" =~ "doltgres" ]] || false | ||
[[ "$output" =~ "postgres" ]] || false | ||
|
||
[ -d "test2/doltgres" ] | ||
[ ! -d "test1/doltgres" ] | ||
} |
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