mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-02 09:10:49 -06:00
allow hyphen in db name to match its dir name (#6995)
This commit is contained in:
@@ -33,8 +33,14 @@ import (
|
||||
)
|
||||
|
||||
var queryDiffDocs = cli.CommandDocumentationContent{
|
||||
ShortDesc: "Shows table diff between two queries",
|
||||
LongDesc: "Will execute two queries and compare the resulting table sets",
|
||||
ShortDesc: "Calculates table diff between two queries",
|
||||
LongDesc: "Will execute two queries and compare the resulting table sets\n\n" +
|
||||
"`<query1>`: A SQL `SELECT` query to be executed.\n\n" +
|
||||
"`<query2>`: A SQL `SELECT` query to be executed.\n\n" +
|
||||
"**Note**\n\n" +
|
||||
"Query diff is performed brute force and thus, will be slow for large result sets.\n" +
|
||||
"The algorithm is super linear (`n^2`) on the size of the results sets.\n" +
|
||||
"Over time, we will optimize this to use features of the storage engine to improve performance.",
|
||||
Synopsis: []string{
|
||||
`[options] [{{.LessThan}}query1{{.GreaterThan}}] [{{.LessThan}}query2{{.GreaterThan}}]`,
|
||||
},
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/commands"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/commands/engine"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
@@ -182,7 +183,7 @@ func (cmd SqlClientCmd) Exec(ctx context.Context, commandStr string, args []stri
|
||||
cli.PrintErrln(color.RedString(err.Error()))
|
||||
return 1
|
||||
}
|
||||
dbToUse = strings.Replace(filepath.Base(directory), "-", "_", -1)
|
||||
dbToUse = dbfactory.DirToDBName(filepath.Base(directory))
|
||||
}
|
||||
format := engine.FormatTabular
|
||||
if hasResultFormat {
|
||||
|
||||
@@ -15,16 +15,21 @@
|
||||
package dbfactory
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dconfig"
|
||||
)
|
||||
|
||||
// DirToDBName takes the physical directory name, |dirName|, and replaces any unsupported characters to create a
|
||||
// valid logical database name. For example, hyphens and spaces are replaced with underscores.
|
||||
// valid logical database name. For example, spaces are replaced with underscores.
|
||||
func DirToDBName(dirName string) string {
|
||||
// this environment variable is used whether to replace hyphens in the database name with underscores.
|
||||
var translateHyphensToUnderscores = os.Getenv(dconfig.EnvDbNameReplaceHyphens) != ""
|
||||
dbName := strings.TrimSpace(dirName)
|
||||
dbName = strings.Map(func(r rune) rune {
|
||||
if unicode.IsSpace(r) || r == '-' {
|
||||
if unicode.IsSpace(r) || (translateHyphensToUnderscores && r == '-') {
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
|
||||
@@ -42,4 +42,5 @@ const (
|
||||
EnvDoltAssistAgree = "DOLT_ASSIST_AGREE"
|
||||
EnvDoltAuthorDate = "DOLT_AUTHOR_DATE"
|
||||
EnvDoltCommitterDate = "DOLT_COMMITTER_DATE"
|
||||
EnvDbNameReplaceHyphens = "DOLT_DBNAME_REPLACE_HYPHENS"
|
||||
)
|
||||
|
||||
29
go/libraries/doltcore/env/multi_repo_env_test.go
vendored
29
go/libraries/doltcore/env/multi_repo_env_test.go
vendored
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dconfig"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/config"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/earl"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
@@ -32,13 +33,29 @@ import (
|
||||
)
|
||||
|
||||
func TestDirToDBName(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
"irs": "irs",
|
||||
replaceHyphenTests := map[string]string{
|
||||
"corona-virus": "corona_virus",
|
||||
" fake - name ": "fake_name",
|
||||
" real - name ": "real_name",
|
||||
}
|
||||
|
||||
for dirName, expected := range tests {
|
||||
err := os.Setenv(dconfig.EnvDbNameReplaceHyphens, "true")
|
||||
require.NoError(t, err)
|
||||
|
||||
for dirName, expected := range replaceHyphenTests {
|
||||
actual := dbfactory.DirToDBName(dirName)
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
allowHyphenTests := map[string]string{
|
||||
"irs": "irs",
|
||||
"corona-virus": "corona-virus",
|
||||
" fake - name ": "fake_-_name",
|
||||
}
|
||||
|
||||
err = os.Setenv(dconfig.EnvDbNameReplaceHyphens, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
for dirName, expected := range allowHyphenTests {
|
||||
actual := dbfactory.DirToDBName(dirName)
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
@@ -116,7 +133,7 @@ func TestMultiEnvForDirectory(t *testing.T) {
|
||||
|
||||
expected := []envCmp{
|
||||
{
|
||||
name: "test_name_123",
|
||||
name: "test---name_123",
|
||||
doltDir: dEnv.GetDoltDir(),
|
||||
},
|
||||
}
|
||||
@@ -147,7 +164,7 @@ func TestMultiEnvForDirectoryWithMultipleRepos(t *testing.T) {
|
||||
assert.Len(t, mrEnv.envs, 3)
|
||||
|
||||
expected := make(map[string]string)
|
||||
expected["test_name_123"] = dEnv.GetDoltDir()
|
||||
expected["test---name_123"] = dEnv.GetDoltDir()
|
||||
expected["abc"] = subEnv1.GetDoltDir()
|
||||
expected["def"] = subEnv2.GetDoltDir()
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ SQL
|
||||
@test "blame: returns an error when the table is not found in the given revision" {
|
||||
run dolt blame HEAD~4 blame_test
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "View 'dolt_repo_$$.dolt_blame_blame_test' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them" ]] || false
|
||||
[[ "$output" =~ "View 'dolt-repo-$$.dolt_blame_blame_test' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them" ]] || false
|
||||
}
|
||||
|
||||
@test "blame: pk ordered output" {
|
||||
|
||||
@@ -92,7 +92,7 @@ setup_test_user() {
|
||||
@test "branch-control: test basic branch write permissions" {
|
||||
setup_test_user
|
||||
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt_repo_$$', 'test-branch', 'test', '%', 'write')"
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt-repo-$$', 'test-branch', 'test', '%', 'write')"
|
||||
dolt branch test-branch
|
||||
|
||||
start_sql_server
|
||||
@@ -120,7 +120,7 @@ setup_test_user() {
|
||||
dolt sql -q "create user test2"
|
||||
dolt sql -q "grant all on *.* to test2"
|
||||
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt_repo_$$', 'test-branch', 'test', '%', 'admin')"
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt-repo-$$', 'test-branch', 'test', '%', 'admin')"
|
||||
dolt branch test-branch
|
||||
|
||||
start_sql_server
|
||||
@@ -134,21 +134,21 @@ setup_test_user() {
|
||||
dolt -u test sql -q "call dolt_checkout('test-branch'); create table t (c1 int)"
|
||||
|
||||
# Admin can make other users
|
||||
dolt -u test sql -q "insert into dolt_branch_control values ('dolt_repo_$$', 'test-branch', 'test2', '%', 'write')"
|
||||
dolt -u test sql -q "insert into dolt_branch_control values ('dolt-repo-$$', 'test-branch', 'test2', '%', 'write')"
|
||||
run dolt -u test sql --result-format csv -q "select * from dolt_branch_control"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "database,branch,user,host,permissions" ]
|
||||
[ ${lines[1]} = "dolt_repo_$$,test-branch,test,%,admin" ]
|
||||
[ ${lines[2]} = "dolt_repo_$$,test-branch,root,localhost,admin" ]
|
||||
[ ${lines[3]} = "dolt_repo_$$,test-branch,test2,%,write" ]
|
||||
[ ${lines[1]} = "dolt-repo-$$,test-branch,test,%,admin" ]
|
||||
[ ${lines[2]} = "dolt-repo-$$,test-branch,root,localhost,admin" ]
|
||||
[ ${lines[3]} = "dolt-repo-$$,test-branch,test2,%,write" ]
|
||||
|
||||
# test2 can see all branch permissions
|
||||
run dolt -u test2 sql --result-format csv -q "select * from dolt_branch_control"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "database,branch,user,host,permissions" ]
|
||||
[ ${lines[1]} = "dolt_repo_$$,test-branch,test,%,admin" ]
|
||||
[ ${lines[2]} = "dolt_repo_$$,test-branch,root,localhost,admin" ]
|
||||
[ ${lines[3]} = "dolt_repo_$$,test-branch,test2,%,write" ]
|
||||
[ ${lines[1]} = "dolt-repo-$$,test-branch,test,%,admin" ]
|
||||
[ ${lines[2]} = "dolt-repo-$$,test-branch,root,localhost,admin" ]
|
||||
[ ${lines[3]} = "dolt-repo-$$,test-branch,test2,%,write" ]
|
||||
|
||||
# test2 now has write permissions on test-branch
|
||||
dolt -u test2 sql -q "call dolt_checkout('test-branch'); insert into t values(0)"
|
||||
@@ -159,7 +159,7 @@ setup_test_user() {
|
||||
run dolt -u test sql --result-format csv -q "select * from dolt_branch_control"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "database,branch,user,host,permissions" ]
|
||||
[ ${lines[1]} = "dolt_repo_$$,test-branch,test,%,admin" ]
|
||||
[ ${lines[1]} = "dolt-repo-$$,test-branch,test,%,admin" ]
|
||||
|
||||
# test2 cannot write to branch
|
||||
run dolt -u test2 sql -q "call dolt_checkout('test-branch'); insert into t values(1)"
|
||||
@@ -170,7 +170,7 @@ setup_test_user() {
|
||||
@test "branch-control: creating a branch grants admin permissions" {
|
||||
setup_test_user
|
||||
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt_repo_$$', 'main', 'test', '%', 'write')"
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt-repo-$$', 'main', 'test', '%', 'write')"
|
||||
|
||||
start_sql_server
|
||||
|
||||
@@ -179,8 +179,8 @@ setup_test_user() {
|
||||
run dolt -u test sql --result-format csv -q "select * from dolt_branch_control"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "database,branch,user,host,permissions" ]
|
||||
[ ${lines[1]} = "dolt_repo_$$,main,test,%,write" ]
|
||||
[ ${lines[2]} = "dolt_repo_$$,test-branch,test,%,admin" ]
|
||||
[ ${lines[1]} = "dolt-repo-$$,main,test,%,write" ]
|
||||
[ ${lines[2]} = "dolt-repo-$$,test-branch,test,%,admin" ]
|
||||
}
|
||||
|
||||
@test "branch-control: test branch namespace control" {
|
||||
@@ -189,16 +189,16 @@ setup_test_user() {
|
||||
dolt sql -q "create user test2"
|
||||
dolt sql -q "grant all on *.* to test2"
|
||||
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt_repo_$$', 'test-
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt-repo-$$', 'test-
|
||||
branch', 'test', '%', 'admin')"
|
||||
dolt sql -q "insert into dolt_branch_namespace_control values ('dolt_repo_$$', 'test-%', 'test2', '%')"
|
||||
dolt sql -q "insert into dolt_branch_namespace_control values ('dolt-repo-$$', 'test-%', 'test2', '%')"
|
||||
|
||||
start_sql_server
|
||||
|
||||
run dolt -u test sql --result-format csv -q "select * from dolt_branch_namespace_control"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "database,branch,user,host" ]
|
||||
[ ${lines[1]} = "dolt_repo_$$,test-%,test2,%" ]
|
||||
[ ${lines[1]} = "dolt-repo-$$,test-%,test2,%" ]
|
||||
|
||||
# test cannot create test-branch
|
||||
run dolt -u test sql -q "call dolt_branch('test-branch')"
|
||||
@@ -215,8 +215,8 @@ branch', 'test', '%', 'admin')"
|
||||
dolt sql -q "create user test2"
|
||||
dolt sql -q "grant all on *.* to test2"
|
||||
|
||||
dolt sql -q "insert into dolt_branch_namespace_control values ('dolt_repo_$$', 'test/%', 'test', '%')"
|
||||
dolt sql -q "insert into dolt_branch_namespace_control values ('dolt_repo_$$', 'test2/%', 'test2', '%')"
|
||||
dolt sql -q "insert into dolt_branch_namespace_control values ('dolt-repo-$$', 'test/%', 'test', '%')"
|
||||
dolt sql -q "insert into dolt_branch_namespace_control values ('dolt-repo-$$', 'test2/%', 'test2', '%')"
|
||||
|
||||
start_sql_server
|
||||
|
||||
@@ -238,8 +238,8 @@ branch', 'test', '%', 'admin')"
|
||||
dolt sql -q "grant all on *.* to admin"
|
||||
dolt sql -q "insert into dolt_branch_control values ('%', '%', 'admin', '%', 'admin')"
|
||||
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt_repo_$$', 'test-branch', 'test', '%', 'read')"
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt_repo_$$', '%', 'test', '%', 'write')"
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt-repo-$$', 'test-branch', 'test', '%', 'read')"
|
||||
dolt sql -q "insert into dolt_branch_control values ('dolt-repo-$$', '%', 'test', '%', 'write')"
|
||||
dolt branch test-branch
|
||||
|
||||
start_sql_server
|
||||
|
||||
@@ -195,7 +195,7 @@ SQL
|
||||
# check information_schema.VIEWS table
|
||||
# TODO: view_definition should be "select `mybin`.`my_users`.`id` AS `id` from `mybin`.`my_users` order by `mybin`.`my_users`.`id`"
|
||||
run dolt sql -q "select * from information_schema.VIEWS;" -r csv
|
||||
[[ "$output" =~ "def,dolt_repo_$$,my_users_view,select id from my_users order by id asc,NONE,YES,root@localhost,DEFINER,utf8mb4,utf8mb4_0900_bin" ]] || false
|
||||
[[ "$output" =~ "def,dolt-repo-$$,my_users_view,select id from my_users order by id asc,NONE,YES,root@localhost,DEFINER,utf8mb4,utf8mb4_0900_bin" ]] || false
|
||||
}
|
||||
|
||||
@test "create-views: view referencing table selects values inserted after it was created" {
|
||||
@@ -292,7 +292,7 @@ SQL
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt sql -q 'select * from all_users'
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "${lines[0]}" =~ "View 'dolt_repo_$$.all_users' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them" ]] || false
|
||||
[[ "${lines[0]}" =~ "View 'dolt-repo-$$.all_users' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them" ]] || false
|
||||
run dolt sql -q 'drop view all_users'
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
@@ -354,7 +354,7 @@ SQL
|
||||
[[ "$output" =~ "select * from t1" ]] || false
|
||||
|
||||
# should use the view definition from branch named, data from branch named
|
||||
run dolt sql -r csv -q "select * from \`dolt_repo_$$/view\`.v1 order by 1"
|
||||
run dolt sql -r csv -q "select * from \`dolt-repo-$$/view\`.v1 order by 1"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
[[ "${lines[1]}" =~ "1,1" ]] || false
|
||||
|
||||
@@ -3,6 +3,7 @@ load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
database_name=dolt_repo_$$
|
||||
|
||||
dolt sql -q "CREATE TABLE test(pk int PRIMARY KEY, color varchar(200))"
|
||||
|
||||
@@ -6,6 +6,7 @@ setup() {
|
||||
skiponwindows "Missing dependencies"
|
||||
|
||||
setup_common
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
|
||||
@@ -889,12 +889,12 @@ SQL
|
||||
dolt sql < ../doltdump.sql
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt sql -q "USE dolt_repo_$$; SHOW TABLES;"
|
||||
run dolt sql -q "USE \`dolt-repo-$$\`; SHOW TABLES;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "table1" ]] || false
|
||||
[[ $output =~ "view1" ]] || false
|
||||
|
||||
run dolt sql -r csv -q "USE dolt_repo_$$; CALL procedure1;"
|
||||
run dolt sql -r csv -q "USE \`dolt-repo-$$\`; CALL procedure1;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "pk,col1" ]] || false
|
||||
[[ $output =~ "2,1" ]] || false
|
||||
|
||||
@@ -143,8 +143,8 @@ SQL
|
||||
|
||||
# check information_schema.TABLE_CONSTRAINTS table
|
||||
run dolt sql -q "select * from information_schema.TABLE_CONSTRAINTS where table_name = 'materials';" -r csv
|
||||
[[ "$output" =~ "def,dolt_repo_$$,PRIMARY,dolt_repo_$$,materials,PRIMARY KEY,YES" ]] || false
|
||||
[[ "$output" =~ "def,dolt_repo_$$,jb6i5huc,dolt_repo_$$,materials,FOREIGN KEY,YES" ]] || false
|
||||
[[ "$output" =~ "def,dolt-repo-$$,PRIMARY,dolt-repo-$$,materials,PRIMARY KEY,YES" ]] || false
|
||||
[[ "$output" =~ "def,dolt-repo-$$,jb6i5huc,dolt-repo-$$,materials,FOREIGN KEY,YES" ]] || false
|
||||
|
||||
# check information_schema.TABLE_CONSTRAINTS_EXTENSIONS table
|
||||
run dolt sql -q "select constraint_name from information_schema.TABLE_CONSTRAINTS_EXTENSIONS where table_name = 'materials';" -r csv
|
||||
|
||||
@@ -1836,7 +1836,7 @@ SQL
|
||||
# Test cloning from a server remote
|
||||
run dolt sql -q "call dolt_clone('http://localhost:50051/test-org/test-repo');"
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt sql -q "use test_repo; show tables;"
|
||||
run dolt sql -q "use \`test-repo\`; show tables;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test_table" ]] || false
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-checkout: DOLT_CHECKOUT updates the head ref session var" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
run dolt sql <<SQL
|
||||
call dolt_checkout('-b', 'feature-branch');
|
||||
select @@dolt_repo_$$_head_ref;
|
||||
@@ -140,6 +141,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-checkout: CALL DOLT_CHECKOUT updates the head ref session var" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
run dolt sql <<SQL
|
||||
CALL DOLT_CHECKOUT('-b', 'feature-branch');
|
||||
select @@dolt_repo_$$_head_ref;
|
||||
@@ -599,7 +601,3 @@ SQL
|
||||
get_head_commit() {
|
||||
dolt log -n 1 | grep -m 1 commit | awk '{print $2}'
|
||||
}
|
||||
|
||||
get_working_hash() {
|
||||
dolt sql -q "select @@dolt_repo_$$_working" | sed -n 4p | sed -e 's/|//' -e 's/|//' -e 's/ //'
|
||||
}
|
||||
|
||||
@@ -134,7 +134,21 @@ teardown() {
|
||||
[[ $output =~ "not found" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-client: handle dashes for implicit database" {
|
||||
@test "sql-client: handle dashes for implicit database with hyphen disabled" {
|
||||
make_repo test-dashes
|
||||
cd test-dashes
|
||||
PORT=$( definePORT )
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
dolt sql-server --user=root --port=$PORT &
|
||||
SERVER_PID=$! # will get killed by teardown_common
|
||||
sleep 5 # not using python wait so this works on windows
|
||||
|
||||
run dolt sql-client -u root -P $PORT -q "show databases"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ " test_dashes " ]] || false
|
||||
}
|
||||
|
||||
@test "sql-client: handle dashes for implicit database with hyphen allowed" {
|
||||
make_repo test-dashes
|
||||
cd test-dashes
|
||||
PORT=$( definePORT )
|
||||
@@ -144,7 +158,7 @@ teardown() {
|
||||
|
||||
run dolt sql-client -u root -P $PORT -q "show databases"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ " test_dashes " ]] || false
|
||||
[[ $output =~ " test-dashes " ]] || false
|
||||
}
|
||||
|
||||
@test "sql-client: select statement prints accurate query timing" {
|
||||
|
||||
@@ -212,6 +212,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-commit: DOLT_COMMIT updates session variables" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
head_variable=@@dolt_repo_$$_head
|
||||
head_commit=$(get_head_commit)
|
||||
run dolt sql << SQL
|
||||
@@ -232,6 +233,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-commit: CALL DOLT_COMMIT updates session variables" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
head_variable=@@dolt_repo_$$_head
|
||||
head_commit=$(get_head_commit)
|
||||
run dolt sql << SQL
|
||||
@@ -252,6 +254,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-commit: DOLT_COMMIT with unstaged tables leaves them in the working set" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
head_variable=@@dolt_repo_$$_head
|
||||
|
||||
run dolt sql << SQL
|
||||
@@ -311,6 +314,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-commit: CALL DOLT_COMMIT with unstaged tables leaves them in the working set" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
head_variable=@@dolt_repo_$$_head
|
||||
|
||||
run dolt sql << SQL
|
||||
|
||||
@@ -22,7 +22,7 @@ SQL
|
||||
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ "$output" =~ "dolt-repo-$$" ]] || false
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
[[ "$output" =~ "mydb" ]] || false
|
||||
|
||||
@@ -43,7 +43,7 @@ SQL
|
||||
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ "$output" =~ "dolt-repo-$$" ]] || false
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
[[ "$output" =~ "mydb" ]] || false
|
||||
|
||||
@@ -65,7 +65,7 @@ SQL
|
||||
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ "$output" =~ "dolt-repo-$$" ]] || false
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
[[ "$output" =~ "mydb" ]] || false
|
||||
|
||||
@@ -142,7 +142,7 @@ SQL
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "mydb2" ]] || false
|
||||
[[ ! "$output" =~ "mydb1" ]] || false
|
||||
[[ ! "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ ! "$output" =~ "dolt-repo-$$" ]] || false
|
||||
|
||||
# data-dir with abs path
|
||||
absdir="/tmp/$$/db_dir"
|
||||
@@ -221,7 +221,7 @@ SQL
|
||||
dolt sql -q "CREATE DATABASE IF NOT EXISTS test;"
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ "$output" =~ "dolt-repo-$$" ]] || false
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
[[ "$output" =~ "test" ]] || false
|
||||
|
||||
@@ -278,7 +278,7 @@ SQL
|
||||
dolt sql -q "CREATE SCHEMA mydb"
|
||||
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[[ "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ "$output" =~ "dolt-repo-$$" ]] || false
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
[[ "$output" =~ "mydb" ]] || false
|
||||
}
|
||||
@@ -311,7 +311,7 @@ SQL
|
||||
|
||||
run dolt sql -q "SHOW DATABASES;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt_repo_$$" ]] || false
|
||||
[[ "$output" =~ "dolt-repo-$$" ]] || false
|
||||
[[ "$output" =~ "information_schema" ]] || false
|
||||
[[ "$output" =~ "metabase" ]] || false
|
||||
|
||||
|
||||
@@ -197,6 +197,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-merge: DOLT_MERGE correctly returns head and working session variables." {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
dolt sql << SQL
|
||||
call dolt_commit('-a', '-m', 'Step 1');
|
||||
call dolt_checkout('-b', 'feature-branch');
|
||||
@@ -316,6 +317,7 @@ SQL
|
||||
}
|
||||
|
||||
@test "sql-merge: DOLT_MERGE -no-ff correctly changes head and working session variables." {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
dolt sql << SQL
|
||||
call dolt_commit('-a', '-m', 'Step 1');
|
||||
call dolt_checkout('-b', 'feature-branch');
|
||||
|
||||
@@ -89,56 +89,6 @@ teardown() {
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DRESET --hard works on unstaged and staged table changes" {
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
run dolt sql -q "CALL DRESET('--hard')"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]] || false
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
dolt add .
|
||||
|
||||
run dolt sql -q "CALL DRESET('--hard')"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]] || false
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
# Reset to head results in clean main.
|
||||
run dolt sql -q "CALL DRESET('--hard', 'head');"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]] || false
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET --hard does not ignore staged docs" {
|
||||
# New docs gets referred as untracked file.
|
||||
echo ~license~ > LICENSE.md
|
||||
dolt docs upload LICENSE.md LICENSE.md
|
||||
dolt add .
|
||||
|
||||
run dolt sql -q "call dolt_reset('--hard')"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
dolt status
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET --hard does not ignore staged docs" {
|
||||
# New docs gets referred as untracked file.
|
||||
echo ~license~ > LICENSE.md
|
||||
@@ -167,29 +117,6 @@ teardown() {
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET --soft works on unstaged and staged table changes" {
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
# Table should still be unstaged
|
||||
run dolt sql -q "call dolt_reset('--soft')"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Changes not staged for commit:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
|
||||
dolt add .
|
||||
|
||||
run dolt sql -q "call dolt_reset('--soft')"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Changes to be committed:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET --soft works on unstaged and staged table changes" {
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
@@ -213,19 +140,6 @@ teardown() {
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET --soft ignores staged docs" {
|
||||
echo ~license~ > LICENSE.md
|
||||
dolt docs upload LICENSE.md LICENSE.md
|
||||
dolt add .
|
||||
|
||||
run dolt sql -q "call dolt_reset('--soft')"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*dolt_docs) ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET --soft ignores staged docs" {
|
||||
echo ~license~ > LICENSE.md
|
||||
dolt docs upload LICENSE.md LICENSE.md
|
||||
@@ -239,29 +153,6 @@ teardown() {
|
||||
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*dolt_docs) ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET works on specific tables" {
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
# Table should still be unstaged
|
||||
run dolt sql -q "call dolt_reset('test')"
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Changes not staged for commit:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
|
||||
dolt sql -q "CREATE TABLE test2 (pk int primary key);"
|
||||
|
||||
dolt add .
|
||||
run dolt sql -q "call dolt_reset('test', 'test2')"
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Changes not staged for commit:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*test2) ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET works on specific tables" {
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
|
||||
@@ -285,45 +176,6 @@ teardown() {
|
||||
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*test2) ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET --soft and --hard on the same table" {
|
||||
# Make a change to the table and do a soft reset
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
run dolt sql -q "call dolt_reset('test')"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Changes not staged for commit:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
|
||||
# Add and unstage the table with a soft reset. Make sure the same data exists.
|
||||
dolt add .
|
||||
|
||||
run dolt sql -q "call dolt_reset('test')"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Changes not staged for commit:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false
|
||||
|
||||
run dolt sql -r csv -q "select * from test"
|
||||
[[ "$output" =~ pk ]] || false
|
||||
[[ "$output" =~ 1 ]] || false
|
||||
|
||||
# Do a hard reset and validate the insert was wiped properly
|
||||
run dolt sql -q "call dolt_reset('--hard')"
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]] || false
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
|
||||
run dolt sql -r csv -q "select * from test"
|
||||
[[ "$output" =~ pk ]] || false
|
||||
[[ "$output" != 1 ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET --soft and --hard on the same table" {
|
||||
# Make a change to the table and do a soft reset
|
||||
dolt sql -q "INSERT INTO test VALUES (1)"
|
||||
@@ -363,28 +215,6 @@ teardown() {
|
||||
[[ "$output" != 1 ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET('--hard') doesn't remove newly created table." {
|
||||
dolt sql << SQL
|
||||
CREATE TABLE test2 (
|
||||
pk int primary key
|
||||
);
|
||||
SQL
|
||||
dolt sql -q "call dolt_reset('--hard');"
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Untracked tables:" ]] || false
|
||||
[[ "$output" =~ ([[:space:]]*new table:[[:space:]]*test2) ]] || false
|
||||
|
||||
dolt add .
|
||||
dolt sql -q "call dolt_reset('--hard');"
|
||||
run dolt status
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]] || false
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET('--hard') doesn't remove newly created table." {
|
||||
dolt sql << SQL
|
||||
CREATE TABLE test2 (
|
||||
@@ -449,20 +279,8 @@ SQL
|
||||
[[ "$output" =~ "true" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET --hard properly maintains session variables." {
|
||||
head_variable=@@dolt_repo_$$_head
|
||||
head_hash=$(get_head_commit)
|
||||
run dolt sql << SQL
|
||||
INSERT INTO test VALUES (1);
|
||||
call dolt_reset('--hard');
|
||||
SELECT $head_variable;
|
||||
SQL
|
||||
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ $head_hash ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET --hard properly maintains session variables." {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
head_variable=@@dolt_repo_$$_head
|
||||
head_hash=$(get_head_commit)
|
||||
run dolt sql << SQL
|
||||
@@ -499,34 +317,8 @@ SQL
|
||||
[[ "$output" =~ "false" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: DOLT_RESET soft maintains staged session variable" {
|
||||
working_hash_var=@@dolt_repo_$$_working
|
||||
run dolt sql -q "SELECT $working_hash_var"
|
||||
working_hash=$output
|
||||
|
||||
run dolt sql << SQL
|
||||
INSERT INTO test VALUES (1);
|
||||
call dolt_add('.');
|
||||
call dolt_reset('test');
|
||||
SELECT $working_hash_var
|
||||
SQL
|
||||
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# These should not match as @@_working should become a new staged hash different from the original working.
|
||||
[[ ! "$output" =~ $working_hash ]] || false
|
||||
|
||||
run dolt sql -q "call dolt_reset('--hard');"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run dolt sql -q "SELECT $working_hash_var"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
# Matches exactly.
|
||||
[[ "$output" = "$working_hash" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-reset: CALL DOLT_RESET soft maintains staged session variable" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
working_hash_var=@@dolt_repo_$$_working
|
||||
run dolt sql -q "SELECT $working_hash_var"
|
||||
working_hash=$output
|
||||
|
||||
@@ -1733,8 +1733,9 @@ behavior:
|
||||
stop_sql_server 1
|
||||
[ ! -d .dolt ]
|
||||
|
||||
run grep "database not found: mydb" server_log.txt
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
run dolt sql -q "SHOW DATABASES"
|
||||
[[ ! "$output" =~ "mydb" ]] || false
|
||||
[[ "$output" =~ "doltdb" ]] || false
|
||||
|
||||
# nested databases inside dropped database should still exist
|
||||
dolt sql -q "SHOW DATABASES"
|
||||
@@ -1756,8 +1757,8 @@ behavior:
|
||||
start_sql_server >> server_log.txt 2>&1
|
||||
dolt sql -q "DROP DATABASE mydb;"
|
||||
|
||||
run grep "database not found: mydb" server_log.txt
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
run dolt sql -q "SHOW DATABASES"
|
||||
[[ ! "$output" =~ "mydb" ]] || false
|
||||
|
||||
[ ! -d .dolt ]
|
||||
|
||||
@@ -1786,6 +1787,26 @@ behavior:
|
||||
[[ "$output" =~ "mydb1" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-server: dropping database with '-' in it but replaced with underscore" {
|
||||
skiponwindows "Missing dependencies"
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
mkdir my-db
|
||||
cd my-db
|
||||
dolt init
|
||||
cd ..
|
||||
|
||||
run dolt sql -q "SHOW DATABASES"
|
||||
[[ "$output" =~ "my_db" ]] || false
|
||||
|
||||
start_sql_server >> server_log.txt 2>&1
|
||||
dolt sql -q "DROP DATABASE my_db;"
|
||||
|
||||
run dolt sql -q "SHOW DATABASES"
|
||||
[[ ! "$output" =~ "my_db" ]] || false
|
||||
|
||||
[ ! -d my-db ]
|
||||
}
|
||||
|
||||
@test "sql-server: dropping database with '-' in it" {
|
||||
skiponwindows "Missing dependencies"
|
||||
|
||||
@@ -1794,11 +1815,14 @@ behavior:
|
||||
dolt init
|
||||
cd ..
|
||||
|
||||
start_sql_server >> server_log.txt 2>&1
|
||||
dolt sql -q "DROP DATABASE my_db;"
|
||||
run dolt sql -q "SHOW DATABASES"
|
||||
[[ "$output" =~ "my-db" ]] || false
|
||||
|
||||
run grep "database not found: my_db" server_log.txt
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
start_sql_server >> server_log.txt 2>&1
|
||||
dolt sql -q "DROP DATABASE \`my-db\`;"
|
||||
|
||||
run dolt sql -q "SHOW DATABASES"
|
||||
[[ ! "$output" =~ "my-db" ]] || false
|
||||
|
||||
[ ! -d my-db ]
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ teardown() {
|
||||
|
||||
# 2 tables are created. 1 from above and 1 in the expect file.
|
||||
[[ "$output" =~ "+---------------------" ]] || false
|
||||
[[ "$output" =~ "| Tables_in_dolt_repo_" ]] || false
|
||||
[[ "$output" =~ "| Tables_in_dolt-repo-" ]] || false
|
||||
[[ "$output" =~ "+---------------------" ]] || false
|
||||
[[ "$output" =~ "| test " ]] || false
|
||||
[[ "$output" =~ "| test_expect " ]] || false
|
||||
|
||||
@@ -3,6 +3,7 @@ load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE one_pk (
|
||||
pk BIGINT NOT NULL,
|
||||
|
||||
@@ -244,9 +244,9 @@ SQL
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "origin" ]] || false
|
||||
|
||||
DATABASE=$(echo $(basename $(pwd)) | tr '-' '_')
|
||||
DATABASE=$(echo $(basename $(pwd)))
|
||||
run dolt sql <<SQL
|
||||
USE $DATABASE/b1;
|
||||
USE \`$DATABASE/b1\`;
|
||||
SELECT name FROM dolt_remotes;
|
||||
SQL
|
||||
[ $status -eq 0 ]
|
||||
|
||||
@@ -12,7 +12,6 @@ setup() {
|
||||
# sql-server starts.
|
||||
mkdir ' drop- me-2 ' && cd ' drop- me-2 '
|
||||
dolt init && cd ..
|
||||
setup_remote_server
|
||||
}
|
||||
|
||||
teardown() {
|
||||
@@ -21,6 +20,7 @@ teardown() {
|
||||
}
|
||||
|
||||
@test "undrop: undrop error messages" {
|
||||
setup_remote_server
|
||||
# When called without any argument, dolt_undrop() returns an error
|
||||
# that includes the database names that can be undropped.
|
||||
run dolt sql -q "CALL dolt_undrop();"
|
||||
@@ -52,18 +52,20 @@ teardown() {
|
||||
}
|
||||
|
||||
@test "undrop: purge error messages" {
|
||||
setup_remote_server
|
||||
# Assert that specifying args when calling dolt_purge_dropped_databases() returns an error
|
||||
run dolt sql -q "call dolt_purge_dropped_databases('all', 'of', 'the', 'dbs');"
|
||||
[ $status -eq 1 ]
|
||||
[[ $output =~ "dolt_purge_dropped_databases does not take any arguments" ]] || false
|
||||
}
|
||||
|
||||
@test "undrop: undrop root database" {
|
||||
@test "undrop: undrop root database with hyphen replaced in its name" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
setup_remote_server
|
||||
# Create a new Dolt database directory to use as a root database
|
||||
# NOTE: We use hyphens here to test how db dirs are renamed.
|
||||
mkdir ' test- db-1 ' && cd ' test- db-1 '
|
||||
dolt init
|
||||
|
||||
# Create some data and a commit in the database
|
||||
dolt sql << EOF
|
||||
create table t1 (pk int primary key, c1 varchar(200));
|
||||
@@ -94,9 +96,48 @@ EOF
|
||||
[[ $output =~ "1,one" ]] || false
|
||||
}
|
||||
|
||||
@test "undrop: undrop root database with hyphen allowed in its name" {
|
||||
setup_remote_server
|
||||
# Create a new Dolt database directory to use as a root database
|
||||
# NOTE: We use hyphens here to test how db dirs are renamed.
|
||||
mkdir ' test- db-1 ' && cd ' test- db-1 '
|
||||
dolt init
|
||||
|
||||
# Create some data and a commit in the database
|
||||
dolt sql << EOF
|
||||
create table t1 (pk int primary key, c1 varchar(200));
|
||||
insert into t1 values (1, "one");
|
||||
call dolt_commit('-Am', 'creating table t1');
|
||||
EOF
|
||||
run dolt sql -q "show databases;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "test-_db-1" ]] || false
|
||||
|
||||
# Drop the root database
|
||||
dolt sql -q "drop database \`test-_db-1\`;"
|
||||
run dolt sql -q "show databases;"
|
||||
[ $status -eq 0 ]
|
||||
[[ ! $output =~ "test-_db-1" ]] || false
|
||||
|
||||
# Undrop the test-_db-1 database
|
||||
# NOTE: After being undropped, the database is no longer the root database,
|
||||
# but contained in a subdirectory like a non-root database.
|
||||
dolt sql -q "call dolt_undrop('test-_db-1');"
|
||||
run dolt sql -q "show databases;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "test-_db-1" ]] || false
|
||||
|
||||
# Sanity check querying some data
|
||||
run dolt sql -r csv -q "select * from \`test-_db-1\`.t1;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "1,one" ]] || false
|
||||
}
|
||||
|
||||
# Asserts that a non-root database can be dropped and then restored with dolt_undrop(), even when
|
||||
# the case of the database name given to dolt_undrop() doesn't match match the original case.
|
||||
@test "undrop: undrop non-root database" {
|
||||
@test "undrop: undrop non-root database with hyphen replaced in its name" {
|
||||
export DOLT_DBNAME_REPLACE_HYPHENS="true"
|
||||
setup_remote_server
|
||||
dolt sql << EOF
|
||||
use drop_me_2;
|
||||
create table t1 (pk int primary key, c1 varchar(200));
|
||||
@@ -124,10 +165,42 @@ EOF
|
||||
[[ $output =~ "1,one" ]] || false
|
||||
}
|
||||
|
||||
# Asserts that a non-root database can be dropped and then restored with dolt_undrop(), even when
|
||||
# the case of the database name given to dolt_undrop() doesn't match match the original case.
|
||||
@test "undrop: undrop non-root database with hyphen allowed in its name" {
|
||||
setup_remote_server
|
||||
dolt sql << EOF
|
||||
use \`drop-_me-2\`;
|
||||
create table t1 (pk int primary key, c1 varchar(200));
|
||||
insert into t1 values (1, "one");
|
||||
call dolt_commit('-Am', 'creating table t1');
|
||||
EOF
|
||||
run dolt sql -q "show databases;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "drop-_me-2" ]] || false
|
||||
|
||||
dolt sql -q "drop database \`drop-_me-2\`;"
|
||||
run dolt sql -q "show databases;"
|
||||
[ $status -eq 0 ]
|
||||
[[ ! $output =~ "drop-_me-2" ]] || false
|
||||
|
||||
# Call dolt_undrop() with non-matching case for the database name to
|
||||
# ensure dolt_undrop() works with case-insensitive database names.
|
||||
dolt sql -q "call dolt_undrop('DrOp-_mE-2');"
|
||||
run dolt sql -q "show databases;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "drop-_me-2" ]] || false
|
||||
|
||||
run dolt sql -r csv -q "select * from \`drop-_me-2\`.t1;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "1,one" ]] || false
|
||||
}
|
||||
|
||||
# When a database is dropped, and then a new database is recreated
|
||||
# with the same name and dropped, dolt_undrop will undrop the most
|
||||
# recent database with that name.
|
||||
@test "undrop: drop database, recreate, and drop again" {
|
||||
setup_remote_server
|
||||
# Create a database named test123
|
||||
dolt sql << EOF
|
||||
create database test123;
|
||||
@@ -170,6 +243,7 @@ EOF
|
||||
# TODO: In the future, it might be useful to allow dolt_undrop() to rename the dropped database to
|
||||
# a new name, but for now, keep it simple and just disallow restoring in this case.
|
||||
@test "undrop: undrop conflict" {
|
||||
setup_remote_server
|
||||
dolt sql << EOF
|
||||
create database dAtAbAsE1;
|
||||
use dAtAbAsE1;
|
||||
@@ -207,6 +281,7 @@ EOF
|
||||
}
|
||||
|
||||
@test "undrop: purging dropped databases" {
|
||||
setup_remote_server
|
||||
# Create a database to keep and a database to purge
|
||||
dolt sql << EOF
|
||||
create database keepme;
|
||||
|
||||
Reference in New Issue
Block a user