From 8ea2847759db086512993e4126eae8ea7a42acca Mon Sep 17 00:00:00 2001 From: jennifersp <44716627+jennifersp@users.noreply.github.com> Date: Thu, 16 Nov 2023 07:25:55 -0800 Subject: [PATCH] allow hyphen in db name to match its dir name (#6995) --- go/cmd/dolt/commands/query_diff.go | 10 +- go/cmd/dolt/commands/sqlserver/sqlclient.go | 3 +- .../doltcore/dbfactory/dirtodbname.go | 9 +- go/libraries/doltcore/dconfig/envvars.go | 1 + .../doltcore/env/multi_repo_env_test.go | 29 ++- integration-tests/bats/blame.bats | 2 +- integration-tests/bats/branch-control.bats | 40 ++-- integration-tests/bats/create-views.bats | 6 +- .../bats/db-revision-specifiers.bats | 1 + integration-tests/bats/deleted-branches.bats | 1 + integration-tests/bats/dump.bats | 4 +- integration-tests/bats/foreign-keys.bats | 4 +- integration-tests/bats/remotes.bats | 2 +- integration-tests/bats/sql-checkout.bats | 6 +- integration-tests/bats/sql-client.bats | 18 +- integration-tests/bats/sql-commit.bats | 4 + .../bats/sql-create-database.bats | 14 +- integration-tests/bats/sql-merge.bats | 2 + integration-tests/bats/sql-reset.bats | 212 +----------------- integration-tests/bats/sql-server.bats | 40 +++- integration-tests/bats/sql-shell.bats | 2 +- integration-tests/bats/sql.bats | 1 + integration-tests/bats/system-tables.bats | 4 +- integration-tests/bats/undrop.bats | 83 ++++++- 24 files changed, 220 insertions(+), 278 deletions(-) diff --git a/go/cmd/dolt/commands/query_diff.go b/go/cmd/dolt/commands/query_diff.go index 877db570d4..42b1616d0d 100644 --- a/go/cmd/dolt/commands/query_diff.go +++ b/go/cmd/dolt/commands/query_diff.go @@ -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" + + "``: A SQL `SELECT` query to be executed.\n\n" + + "``: 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}}]`, }, diff --git a/go/cmd/dolt/commands/sqlserver/sqlclient.go b/go/cmd/dolt/commands/sqlserver/sqlclient.go index 25ceb5e722..ec218244b1 100644 --- a/go/cmd/dolt/commands/sqlserver/sqlclient.go +++ b/go/cmd/dolt/commands/sqlserver/sqlclient.go @@ -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 { diff --git a/go/libraries/doltcore/dbfactory/dirtodbname.go b/go/libraries/doltcore/dbfactory/dirtodbname.go index 734415f0cf..dc0d486fb2 100644 --- a/go/libraries/doltcore/dbfactory/dirtodbname.go +++ b/go/libraries/doltcore/dbfactory/dirtodbname.go @@ -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 diff --git a/go/libraries/doltcore/dconfig/envvars.go b/go/libraries/doltcore/dconfig/envvars.go index b3aa3e3086..630ff5a206 100755 --- a/go/libraries/doltcore/dconfig/envvars.go +++ b/go/libraries/doltcore/dconfig/envvars.go @@ -42,4 +42,5 @@ const ( EnvDoltAssistAgree = "DOLT_ASSIST_AGREE" EnvDoltAuthorDate = "DOLT_AUTHOR_DATE" EnvDoltCommitterDate = "DOLT_COMMITTER_DATE" + EnvDbNameReplaceHyphens = "DOLT_DBNAME_REPLACE_HYPHENS" ) diff --git a/go/libraries/doltcore/env/multi_repo_env_test.go b/go/libraries/doltcore/env/multi_repo_env_test.go index f21a421986..b8bfadd1a0 100644 --- a/go/libraries/doltcore/env/multi_repo_env_test.go +++ b/go/libraries/doltcore/env/multi_repo_env_test.go @@ -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() diff --git a/integration-tests/bats/blame.bats b/integration-tests/bats/blame.bats index 15d084538f..82abb175d3 100644 --- a/integration-tests/bats/blame.bats +++ b/integration-tests/bats/blame.bats @@ -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" { diff --git a/integration-tests/bats/branch-control.bats b/integration-tests/bats/branch-control.bats index 34f8c94dd8..4c8afa859b 100644 --- a/integration-tests/bats/branch-control.bats +++ b/integration-tests/bats/branch-control.bats @@ -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 diff --git a/integration-tests/bats/create-views.bats b/integration-tests/bats/create-views.bats index a62f857776..e104202301 100644 --- a/integration-tests/bats/create-views.bats +++ b/integration-tests/bats/create-views.bats @@ -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 diff --git a/integration-tests/bats/db-revision-specifiers.bats b/integration-tests/bats/db-revision-specifiers.bats index 8c2e5681f2..154c1591fa 100644 --- a/integration-tests/bats/db-revision-specifiers.bats +++ b/integration-tests/bats/db-revision-specifiers.bats @@ -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))" diff --git a/integration-tests/bats/deleted-branches.bats b/integration-tests/bats/deleted-branches.bats index 6c1b7036dc..036e59ffc6 100644 --- a/integration-tests/bats/deleted-branches.bats +++ b/integration-tests/bats/deleted-branches.bats @@ -6,6 +6,7 @@ setup() { skiponwindows "Missing dependencies" setup_common + export DOLT_DBNAME_REPLACE_HYPHENS="true" } teardown() { diff --git a/integration-tests/bats/dump.bats b/integration-tests/bats/dump.bats index 2fe7fe8872..3954f4e9ac 100644 --- a/integration-tests/bats/dump.bats +++ b/integration-tests/bats/dump.bats @@ -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 diff --git a/integration-tests/bats/foreign-keys.bats b/integration-tests/bats/foreign-keys.bats index 4fbbfa4eb3..ea53d6a59a 100644 --- a/integration-tests/bats/foreign-keys.bats +++ b/integration-tests/bats/foreign-keys.bats @@ -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 diff --git a/integration-tests/bats/remotes.bats b/integration-tests/bats/remotes.bats index 59b39e310e..76698efc6d 100644 --- a/integration-tests/bats/remotes.bats +++ b/integration-tests/bats/remotes.bats @@ -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 } diff --git a/integration-tests/bats/sql-checkout.bats b/integration-tests/bats/sql-checkout.bats index 4a1dd6577d..21c0ca4d86 100644 --- a/integration-tests/bats/sql-checkout.bats +++ b/integration-tests/bats/sql-checkout.bats @@ -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 < 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 diff --git a/integration-tests/bats/sql-server.bats b/integration-tests/bats/sql-server.bats index 1f3e4bde1a..31fd83e4b2 100644 --- a/integration-tests/bats/sql-server.bats +++ b/integration-tests/bats/sql-server.bats @@ -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 ] } diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index c6788ff10b..3df3d335af 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -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 diff --git a/integration-tests/bats/sql.bats b/integration-tests/bats/sql.bats index 6f7bf58381..e44324d5e6 100755 --- a/integration-tests/bats/sql.bats +++ b/integration-tests/bats/sql.bats @@ -3,6 +3,7 @@ load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common + export DOLT_DBNAME_REPLACE_HYPHENS="true" dolt sql <