diff --git a/go/cmd/dolt/commands/sqlserver/server_test.go b/go/cmd/dolt/commands/sqlserver/server_test.go index ec26de9336..4af85cacc9 100644 --- a/go/cmd/dolt/commands/sqlserver/server_test.go +++ b/go/cmd/dolt/commands/sqlserver/server_test.go @@ -312,11 +312,11 @@ func TestServerSetDefaultBranch(t *testing.T) { expectedRes: []testBranch{{defaultBranch}}, }, { - query: sess.Select("dolt_checkout('-b', 'new')"), + query: sess.SelectBySql("call dolt_checkout('-b', 'new')"), expectedRes: []testBranch{{""}}, }, { - query: sess.Select("dolt_checkout('main')"), + query: sess.SelectBySql("call dolt_checkout('main')"), expectedRes: []testBranch{{""}}, }, } @@ -461,7 +461,7 @@ func TestReadReplica(t *testing.T) { var res []int - q := sess.SelectBySql(fmt.Sprintf("select dolt_checkout('%s')", newBranch)) + q := sess.SelectBySql(fmt.Sprintf("call dolt_checkout('%s')", newBranch)) _, err = q.LoadContext(context.Background(), &res) require.NoError(t, err) assert.ElementsMatch(t, res, []int{0}) diff --git a/go/libraries/doltcore/sqle/dfunctions/commit.go b/go/libraries/doltcore/sqle/dfunctions/commit.go deleted file mode 100644 index b8e2838212..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/commit.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2020 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" -) - -const CommitFuncName = "commit" - -// Deprecated: please use the version in the dprocedures package -type CommitFunc struct { - children []sql.Expression -} - -// NewCommitFunc creates a new CommitFunc expression. -// Deprecated: please use the version in the dprocedures package -func NewCommitFunc(args ...sql.Expression) (sql.Expression, error) { - return &CommitFunc{children: args}, nil -} - -// Eval implements the Expression interface. -func (cf *CommitFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, cf.Children()) - if err != nil { - return noConflictsOrViolations, err - } - return DoDoltCommit(ctx, args) -} - -// String implements the Stringer interface. -func (cf *CommitFunc) String() string { - childrenStrings := make([]string, len(cf.children)) - - for i, child := range cf.children { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("COMMIT(%s)", strings.Join(childrenStrings, ",")) -} - -// IsNullable implements the Expression interface. -func (cf *CommitFunc) IsNullable() bool { - return false -} - -func (cf *CommitFunc) Resolved() bool { - for _, child := range cf.Children() { - if !child.Resolved() { - return false - } - } - return true -} - -func (cf *CommitFunc) Children() []sql.Expression { - return cf.children -} - -// WithChildren implements the Expression interface. -func (cf *CommitFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewCommitFunc(children...) -} - -func (cf *CommitFunc) Type() sql.Type { - return sql.Text -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_add.go b/go/libraries/doltcore/sqle/dfunctions/dolt_add.go deleted file mode 100644 index d3d3d14e51..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_add.go +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2020 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" -) - -const DoltAddFuncName = "dolt_add" - -// Deprecated: please use the version in the dprocedures package -type DoltAddFunc struct { - children []sql.Expression -} - -func (d DoltAddFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return 1, err - } - return DoDoltAdd(ctx, args) -} - -func DoDoltAdd(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return 1, fmt.Errorf("Empty database name.") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return 1, err - } - - apr, err := cli.CreateAddArgParser().Parse(args) - if err != nil { - return 1, err - } - - allFlag := apr.Contains(cli.AllFlag) - - dSess := dsess.DSessFromSess(ctx.Session) - roots, ok := dSess.GetRoots(ctx, dbName) - if apr.NArg() == 0 && !allFlag { - return 1, fmt.Errorf("Nothing specified, nothing added. Maybe you wanted to say 'dolt add .'?") - } else if allFlag || apr.NArg() == 1 && apr.Arg(0) == "." { - if !ok { - return 1, fmt.Errorf("db session not found") - } - - roots, err = actions.StageAllTables(ctx, roots) - if err != nil { - return 1, err - } - - err = dSess.SetRoots(ctx, dbName, roots) - if err != nil { - return 1, err - } - } else { - roots, err = actions.StageTables(ctx, roots, apr.Args) - if err != nil { - return 1, err - } - - err = dSess.SetRoots(ctx, dbName, roots) - if err != nil { - return 1, err - } - } - - return 0, nil -} - -func (d DoltAddFunc) Resolved() bool { - for _, child := range d.Children() { - if !child.Resolved() { - return false - } - } - return true -} - -func (d DoltAddFunc) String() string { - childrenStrings := make([]string, len(d.children)) - - for i, child := range d.children { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_ADD(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltAddFunc) Type() sql.Type { - return sql.Int8 -} - -func (d DoltAddFunc) IsNullable() bool { - for _, child := range d.Children() { - if child.IsNullable() { - return true - } - } - return false -} - -func (d DoltAddFunc) Children() []sql.Expression { - return d.children -} - -func (d DoltAddFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltAddFunc(children...) -} - -// NewDoltAddFunc creates a new DoltAddFunc expression whose children represents the args passed in DOLT_ADD. -// Deprecated: please use the version in the dprocedures package -func NewDoltAddFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltAddFunc{children: args}, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_backup.go b/go/libraries/doltcore/sqle/dfunctions/dolt_backup.go deleted file mode 100644 index e20f8fbb1a..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_backup.go +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright 2022 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/dbfactory" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/libraries/utils/filesys" - "github.com/dolthub/dolt/go/store/datas/pull" -) - -const ( - DoltBackupFuncName = "dolt_backup" - - statusOk = 1 - statusErr = 0 -) - -// Deprecated: please use the version in the dprocedures package -type DoltBackupFunc struct { - expression.NaryExpression -} - -// Deprecated: please use the version in the dprocedures package -func NewDoltBackupFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltBackupFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -func (d DoltBackupFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_BACKUP(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltBackupFunc) Type() sql.Type { - return sql.Int8 -} - -func (d DoltBackupFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltBackupFunc(children...) -} - -func (d DoltBackupFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return statusErr, err - } - return DoDoltBackup(ctx, args) -} - -func DoDoltBackup(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - if len(dbName) == 0 { - return statusErr, fmt.Errorf("Empty database name.") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return statusErr, err - } - - apr, err := cli.CreateBackupArgParser().Parse(args) - if err != nil { - return statusErr, err - } - - invalidParams := []string{dbfactory.AWSCredsFileParam, dbfactory.AWSCredsProfile, dbfactory.AWSCredsTypeParam, dbfactory.AWSRegionParam} - for _, param := range invalidParams { - if apr.Contains(param) { - return statusErr, fmt.Errorf("parameter '%s' is not supported when running this command via SQL", param) - } - } - - sess := dsess.DSessFromSess(ctx.Session) - dbData, ok := sess.GetDbData(ctx, dbName) - if !ok { - return statusErr, sql.ErrDatabaseNotFound.New(dbName) - } - - var b env.Remote - switch { - case apr.NArg() == 0: - return statusErr, fmt.Errorf("listing existing backups endpoints in sql is unimplemented.") - case apr.Arg(0) == cli.AddBackupId: - return statusErr, fmt.Errorf("adding backup endpoint in sql is unimplemented.") - case apr.Arg(0) == cli.RemoveBackupId: - return statusErr, fmt.Errorf("removing backup endpoint in sql is unimplemented.") - case apr.Arg(0) == cli.RemoveBackupShortId: - return statusErr, fmt.Errorf("removing backup endpoint in sql is unimplemented.") - case apr.Arg(0) == cli.RestoreBackupId: - return statusErr, fmt.Errorf("restoring backup endpoint in sql is unimplemented.") - case apr.Arg(0) == cli.SyncBackupUrlId: - if apr.NArg() != 2 { - return statusErr, fmt.Errorf("usage: dolt_backup('sync-url', BACKUP_URL)") - } - - backupUrl := strings.TrimSpace(apr.Arg(1)) - cfg := loadConfig(ctx) - scheme, absBackupUrl, err := env.GetAbsRemoteUrl(filesys.LocalFS, cfg, backupUrl) - if err != nil { - return statusErr, fmt.Errorf("error: '%s' is not valid.", backupUrl) - } else if scheme == dbfactory.HTTPScheme || scheme == dbfactory.HTTPSScheme { - // not sure how to get the dialer so punting on this - return statusErr, fmt.Errorf("sync-url does not support http or https backup locations currently") - } - - params, err := cli.ProcessBackupArgs(apr, scheme, absBackupUrl) - if err != nil { - return statusErr, err - } - - credsFile, _ := sess.GetSessionVariable(ctx, dsess.AwsCredsFile) - credsFileStr, isStr := credsFile.(string) - if isStr && len(credsFileStr) > 0 { - params[dbfactory.AWSCredsFileParam] = credsFileStr - } - - credsProfile, err := sess.GetSessionVariable(ctx, dsess.AwsCredsProfile) - profStr, isStr := credsProfile.(string) - if isStr && len(profStr) > 0 { - params[dbfactory.AWSCredsProfile] = profStr - } - - credsRegion, err := sess.GetSessionVariable(ctx, dsess.AwsCredsRegion) - regionStr, isStr := credsRegion.(string) - if isStr && len(regionStr) > 0 { - params[dbfactory.AWSRegionParam] = regionStr - } - - b = env.NewRemote("__temp__", backupUrl, params) - - case apr.Arg(0) == cli.SyncBackupId: - if apr.NArg() != 2 { - return statusErr, fmt.Errorf("usage: dolt_backup('sync', BACKUP_NAME)") - } - - backupName := strings.TrimSpace(apr.Arg(1)) - - backups, err := dbData.Rsr.GetBackups() - if err != nil { - return statusErr, err - } - - b, ok = backups[backupName] - if !ok { - return statusErr, fmt.Errorf("error: unknown backup: '%s'; %v", backupName, backups) - } - - default: - return statusErr, fmt.Errorf("unrecognized dolt_backup parameter: %s", apr.Arg(0)) - } - - destDb, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, b, true) - if err != nil { - return statusErr, fmt.Errorf("error loading backup destination: %w", err) - } - - tmpDir, err := dbData.Rsw.TempTableFilesDir() - if err != nil { - return statusErr, err - } - err = actions.SyncRoots(ctx, dbData.Ddb, destDb, tmpDir, runProgFuncs, stopProgFuncs) - if err != nil && err != pull.ErrDBUpToDate { - return 1, fmt.Errorf("error syncing backup: %w", err) - } - return statusOk, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_branch.go b/go/libraries/doltcore/sqle/dfunctions/dolt_branch.go deleted file mode 100644 index 52660f7734..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_branch.go +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "errors" - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/ref" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/libraries/doltcore/sqlserver" - "github.com/dolthub/dolt/go/libraries/utils/argparser" - "github.com/dolthub/dolt/go/libraries/utils/filesys" -) - -const DoltBranchFuncName = "dolt_branch" - -var EmptyBranchNameErr = errors.New("error: cannot branch empty string") -var InvalidArgErr = errors.New("error: invalid usage") - -// Deprecated: please use the version in the dprocedures package -type DoltBranchFunc struct { - expression.NaryExpression -} - -// Deprecated: please use the version in the dprocedures package -func NewDoltBranchFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltBranchFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -func (d DoltBranchFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_BRANCH(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltBranchFunc) Type() sql.Type { - return sql.Int8 -} - -func (d DoltBranchFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltBranchFunc(children...) -} - -func (d DoltBranchFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return 1, err - } - return DoDoltBranch(ctx, args) -} - -func DoDoltBranch(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return 1, fmt.Errorf("Empty database name.") - } - - apr, err := cli.CreateBranchArgParser().Parse(args) - if err != nil { - return 1, err - } - - dSess := dsess.DSessFromSess(ctx.Session) - dbData, ok := dSess.GetDbData(ctx, dbName) - if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - switch { - case apr.Contains(cli.CopyFlag): - err = copyBranch(ctx, dbData, apr) - case apr.Contains(cli.MoveFlag): - err = renameBranch(ctx, dbData, apr, dSess, dbName) - case apr.Contains(cli.DeleteFlag), apr.Contains(cli.DeleteForceFlag): - err = deleteBranches(ctx, dbData, apr, dSess, dbName) - default: - err = createNewBranch(ctx, dbData, apr) - } - - if err != nil { - return 1, err - } else { - return 0, nil - } -} - -// renameBranch takes DoltSession and database name to try accessing file system for dolt database. -// If the oldBranch being renamed is the current branch on CLI, then RepoState head will be updated with the newBranch ref. -func renameBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string) error { - if apr.NArg() != 2 { - return InvalidArgErr - } - oldBranchName, newBranchName := apr.Arg(0), apr.Arg(1) - if oldBranchName == "" || newBranchName == "" { - return EmptyBranchNameErr - } - if err := branch_control.CanDeleteBranch(ctx, oldBranchName); err != nil { - return err - } - if err := branch_control.CanCreateBranch(ctx, newBranchName); err != nil { - return err - } - force := apr.Contains(cli.ForceFlag) - - if !force { - err := validateBranchNotActiveInAnySession(ctx, oldBranchName) - if err != nil { - return err - } - } else if err := branch_control.CanDeleteBranch(ctx, newBranchName); err != nil { - // If force is enabled, we can overwrite the destination branch, so we require a permission check here, even if the - // destination branch doesn't exist. An unauthorized user could simply rerun the command without the force flag. - return err - } - - err := actions.RenameBranch(ctx, dbData, loadConfig(ctx), oldBranchName, newBranchName, force) - if err != nil { - return err - } - err = branch_control.AddAdminForContext(ctx, newBranchName) - if err != nil { - return err - } - - // The current branch on CLI can be deleted as user can be on different branch on SQL and delete it from SQL session. - // To update current head info on RepoState, we need DoltEnv to load CLI environment. - if fs, err := sess.Provider().FileSystemForDatabase(dbName); err == nil { - if repoState, err := env.LoadRepoState(fs); err == nil { - if repoState.Head.Ref.GetPath() == oldBranchName { - repoState.Head.Ref = ref.NewBranchRef(newBranchName) - repoState.Save(fs) - } - } - } - - return nil -} - -// deleteBranches takes DoltSession and database name to try accessing file system for dolt database. -// If the database is not session state db and the branch being deleted is the current branch on CLI, it will update -// the RepoState to set head as empty branchRef. -func deleteBranches(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string) error { - if apr.NArg() == 0 { - return InvalidArgErr - } - - // The current branch on CLI can be deleted as user can be on different branch on SQL and delete it from SQL session. - // To update current head info on RepoState, we need DoltEnv to load CLI environment. - var rs *env.RepoState - var headOnCLI string - fs, err := sess.Provider().FileSystemForDatabase(dbName) - if err == nil { - if repoState, err := env.LoadRepoState(fs); err == nil { - rs = repoState - headOnCLI = repoState.Head.Ref.GetPath() - } - } - - // Verify that we can delete all branches before continuing - for _, branchName := range apr.Args { - if err = branch_control.CanDeleteBranch(ctx, branchName); err != nil { - return err - } - } - - var updateFS = false - for _, branchName := range apr.Args { - if len(branchName) == 0 { - return EmptyBranchNameErr - } - force := apr.Contains(cli.DeleteForceFlag) || apr.Contains(cli.ForceFlag) - - if !force { - err = validateBranchNotActiveInAnySession(ctx, branchName) - if err != nil { - return err - } - } - err = actions.DeleteBranch(ctx, dbData, loadConfig(ctx), branchName, actions.DeleteOptions{ - Force: force, - }) - if err != nil { - return err - } - if headOnCLI == branchName { - updateFS = true - } - } - - if fs != nil && updateFS { - rs.Head.Ref = ref.NewBranchRef("") - rs.Save(fs) - } - - return nil -} - -// validateBranchNotActiveInAnySessions returns an error if the specified branch is currently -// selected as the active branch for any active server sessions. -func validateBranchNotActiveInAnySession(ctx *sql.Context, branchName string) error { - currentDbName, _, err := getRevisionForRevisionDatabase(ctx, ctx.GetCurrentDatabase()) - if err != nil { - return err - } - - if currentDbName == "" { - return nil - } - - if sqlserver.RunningInServerMode() == false { - return nil - } - - runningServer := sqlserver.GetRunningServer() - if runningServer == nil { - return nil - } - sessionManager := runningServer.SessionManager() - branchRef := ref.NewBranchRef(branchName) - - return sessionManager.Iter(func(session sql.Session) (bool, error) { - dsess, ok := session.(*dsess.DoltSession) - if !ok { - return false, fmt.Errorf("unexpected session type: %T", session) - } - - sessionDatabase := dsess.Session.GetCurrentDatabase() - sessionDbName, _, err := getRevisionForRevisionDatabase(ctx, dsess.GetCurrentDatabase()) - if err != nil { - return false, err - } - - if len(sessionDatabase) == 0 || sessionDbName != currentDbName { - return false, nil - } - - activeBranchRef, err := dsess.CWBHeadRef(ctx, sessionDatabase) - if err != nil { - return false, err - } - - if ref.Equals(branchRef, activeBranchRef) { - return false, fmt.Errorf("unsafe to delete or rename branches in use in other sessions; " + - "use --force to force the change") - } - - return false, nil - }) -} - -func loadConfig(ctx *sql.Context) *env.DoltCliConfig { - // When executing branch actions from SQL, we don't have access to a DoltEnv like we do from - // within the CLI. We can fake it here enough to get a DoltCliConfig, but we can't rely on the - // DoltEnv because tests and production will run with different settings (e.g. in-mem versus file). - dEnv := env.Load(ctx, env.GetCurrentUserHomeDir, filesys.LocalFS, doltdb.LocalDirDoltDB, "") - return dEnv.Config -} - -func createNewBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults) error { - var branchName string - var startPt = "HEAD" - if apr.NArg() == 1 { - branchName = apr.Arg(0) - } else if apr.NArg() == 2 { - branchName = apr.Arg(0) - startPt = apr.Arg(1) - if len(startPt) == 0 { - return InvalidArgErr - } - } - - if len(branchName) == 0 { - return EmptyBranchNameErr - } - - if err := branch_control.CanCreateBranch(ctx, branchName); err != nil { - return err - } - return actions.CreateBranchWithStartPt(ctx, dbData, branchName, startPt, apr.Contains(cli.ForceFlag)) -} - -func copyBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults) error { - if apr.NArg() != 2 { - return InvalidArgErr - } - - srcBr := apr.Args[0] - if len(srcBr) == 0 { - return EmptyBranchNameErr - } - - destBr := apr.Args[1] - if len(destBr) == 0 { - return EmptyBranchNameErr - } - - force := apr.Contains(cli.ForceFlag) - return copyABranch(ctx, dbData, srcBr, destBr, force) -} - -func copyABranch(ctx *sql.Context, dbData env.DbData, srcBr string, destBr string, force bool) error { - if err := branch_control.CanCreateBranch(ctx, destBr); err != nil { - return err - } - // If force is enabled, we can overwrite the destination branch, so we require a permission check here, even if the - // destination branch doesn't exist. An unauthorized user could simply rerun the command without the force flag. - if force { - if err := branch_control.CanDeleteBranch(ctx, destBr); err != nil { - return err - } - } - err := actions.CopyBranchOnDB(ctx, dbData.Ddb, srcBr, destBr, force) - if err != nil { - if err == doltdb.ErrBranchNotFound { - return errors.New(fmt.Sprintf("fatal: A branch named '%s' not found", srcBr)) - } else if err == actions.ErrAlreadyExists { - return errors.New(fmt.Sprintf("fatal: A branch named '%s' already exists.", destBr)) - } else if err == doltdb.ErrInvBranchName { - return errors.New(fmt.Sprintf("fatal: '%s' is not a valid branch name.", destBr)) - } else { - return errors.New(fmt.Sprintf("fatal: Unexpected error copying branch from '%s' to '%s'", srcBr, destBr)) - } - } - err = branch_control.AddAdminForContext(ctx, destBr) - if err != nil { - return err - } - - return nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_checkout.go b/go/libraries/doltcore/sqle/dfunctions/dolt_checkout.go deleted file mode 100644 index 0bf3b58d8d..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_checkout.go +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "errors" - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/cmd/dolt/errhand" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/ref" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/store/hash" -) - -const DoltCheckoutFuncName = "dolt_checkout" - -var ErrEmptyBranchName = errors.New("error: cannot checkout empty string") - -// Deprecated: please use the version in the dprocedures package -type DoltCheckoutFunc struct { - expression.NaryExpression -} - -func (d DoltCheckoutFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return 1, err - } - return DoDoltCheckout(ctx, args) -} - -func DoDoltCheckout(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return 1, fmt.Errorf("Empty database name.") - } - - dbName, _, err := getRevisionForRevisionDatabase(ctx, dbName) - if err != nil { - return -1, err - } - - apr, err := cli.CreateCheckoutArgParser().Parse(args) - if err != nil { - return 1, err - } - - if (apr.Contains(cli.CheckoutCoBranch) && apr.NArg() > 1) || (!apr.Contains(cli.CheckoutCoBranch) && apr.NArg() == 0) { - return 1, errors.New("Improper usage.") - } - - // Checking out new branch. - dSess := dsess.DSessFromSess(ctx.Session) - dbData, ok := dSess.GetDbData(ctx, dbName) - if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - if newBranch, newBranchOk := apr.GetValue(cli.CheckoutCoBranch); newBranchOk { - if len(newBranch) == 0 { - err = errors.New("error: cannot checkout empty string") - } else if len(apr.Args) > 0 { - err = checkoutNewBranch(ctx, dbName, dbData, newBranch, apr.Arg(0)) - } else { - err = checkoutNewBranch(ctx, dbName, dbData, newBranch, "") - } - - if err != nil { - return 1, err - } - - return 0, nil - } - - name := apr.Arg(0) - if len(name) == 0 { - return 1, ErrEmptyBranchName - } - - // Check if user wants to checkout branch. - if isBranch, err := actions.IsBranch(ctx, dbData.Ddb, name); err != nil { - return 1, err - } else if isBranch { - err = checkoutBranch(ctx, dbName, name) - if errors.Is(err, doltdb.ErrWorkingSetNotFound) { - // If there is a branch but there is no working set, - // somehow the local branch ref was created without a - // working set. This happened with old versions of dolt - // when running as a read replica, for example. Try to - // create a working set pointing at the existing branch - // HEAD and check out the branch again. - // - // TODO: This is all quite racey, but so is the - // handling in DoltDB, etc. - err = createWorkingSetForLocalBranch(ctx, dbData.Ddb, name) - if err != nil { - return 1, err - } - - err = checkoutBranch(ctx, dbName, name) - } - if err != nil { - return 1, err - } - return 0, nil - } - - roots, ok := dSess.GetRoots(ctx, dbName) - if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - err = checkoutTables(ctx, roots, dbName, args) - if err != nil && apr.NArg() == 1 { - err = checkoutRemoteBranch(ctx, dbName, dbData, name) - } - - if err != nil { - return 1, err - } - - return 0, nil -} - -// createWorkingSetForLocalBranch will make a new working set for a local -// branch ref if one does not already exist. Can be used to fix up local branch -// state when branches have been created without working sets in the past. -// -// This makes it so that dolt_checkout can checkout workingset-less branches, -// the same as `dolt checkout` at the CLI. The semantics of exactly what -// working set gets created in the new case are different, since the CLI takes -// the working set with it. -// -// TODO: This is cribbed heavily from doltdb.*DoltDB.NewBranchAtCommit. -func createWorkingSetForLocalBranch(ctx *sql.Context, ddb *doltdb.DoltDB, branchName string) error { - branchRef := ref.NewBranchRef(branchName) - commit, err := ddb.ResolveCommitRef(ctx, branchRef) - if err != nil { - return err - } - - commitRoot, err := commit.GetRootValue(ctx) - if err != nil { - return err - } - - wsRef, err := ref.WorkingSetRefForHead(branchRef) - if err != nil { - return err - } - - _, err = ddb.ResolveWorkingSet(ctx, wsRef) - if err == nil { - // This already exists. Return... - return nil - } - if !errors.Is(err, doltdb.ErrWorkingSetNotFound) { - return err - } - - ws := doltdb.EmptyWorkingSet(wsRef).WithWorkingRoot(commitRoot).WithStagedRoot(commitRoot) - return ddb.UpdateWorkingSet(ctx, wsRef, ws, hash.Hash{} /* current hash... */, doltdb.TodoWorkingSetMeta()) -} - -// getRevisionForRevisionDatabase returns the root database name and revision for a database, or just the root database name if the specified db name is not a revision database. -func getRevisionForRevisionDatabase(ctx *sql.Context, dbName string) (string, string, error) { - doltsess, ok := ctx.Session.(*dsess.DoltSession) - if !ok { - return "", "", fmt.Errorf("unexpected session type: %T", ctx.Session) - } - - provider := doltsess.Provider() - return provider.GetRevisionForRevisionDatabase(ctx, dbName) -} - -// checkoutRemoteBranch checks out a remote branch creating a new local branch with the same name as the remote branch -// and set its upstream. The upstream persists out of sql session. -func checkoutRemoteBranch(ctx *sql.Context, dbName string, dbData env.DbData, branchName string) error { - remoteRefs, err := actions.GetRemoteBranchRef(ctx, dbData.Ddb, branchName) - if err != nil { - return errors.New("fatal: unable to read from data repository") - } - - if len(remoteRefs) == 0 { - return fmt.Errorf("error: could not find %s", branchName) - } else if len(remoteRefs) == 1 { - remoteRef := remoteRefs[0] - err := checkoutNewBranch(ctx, dbName, dbData, branchName, remoteRef.String()) - if err != nil { - return err - } - - refSpec, err := ref.ParseRefSpecForRemote(remoteRef.GetRemote(), remoteRef.GetBranch()) - if err != nil { - return errhand.BuildDError(fmt.Errorf("%w: '%s'", err, remoteRef.GetRemote()).Error()).Build() - } - - src := refSpec.SrcRef(dbData.Rsr.CWBHeadRef()) - dest := refSpec.DestRef(src) - - return dbData.Rsw.UpdateBranch(src.GetPath(), env.BranchConfig{ - Merge: ref.MarshalableRef{ - Ref: dest, - }, - Remote: remoteRef.GetRemote(), - }) - } else { - return fmt.Errorf("'%s' matched multiple (%v) remote tracking branches", branchName, len(remoteRefs)) - } -} - -func checkoutNewBranch(ctx *sql.Context, dbName string, dbData env.DbData, branchName, startPt string) error { - if len(branchName) == 0 { - return ErrEmptyBranchName - } - - if startPt == "" { - startPt = "head" - } - - err := actions.CreateBranchWithStartPt(ctx, dbData, branchName, startPt, false) - if err != nil { - return err - } - - return checkoutBranch(ctx, dbName, branchName) -} - -func checkoutBranch(ctx *sql.Context, dbName string, branchName string) error { - wsRef, err := ref.WorkingSetRefForHead(ref.NewBranchRef(branchName)) - if err != nil { - return err - } - - if ctx.GetCurrentDatabase() != dbName { - ctx.SetCurrentDatabase(dbName) - } - - dSess := dsess.DSessFromSess(ctx.Session) - return dSess.SwitchWorkingSet(ctx, dbName, wsRef) -} - -func checkoutTables(ctx *sql.Context, roots doltdb.Roots, name string, tables []string) error { - roots, err := actions.MoveTablesFromHeadToWorking(ctx, roots, tables) - - if err != nil { - if doltdb.IsRootValUnreachable(err) { - rt := doltdb.GetUnreachableRootType(err) - return fmt.Errorf("error: unable to read the %s", rt.String()) - } else if actions.IsTblNotExist(err) { - return fmt.Errorf("error: given tables do not exist") - } else { - return fmt.Errorf("fatal: Unexpected error checking out tables") - } - } - - dSess := dsess.DSessFromSess(ctx.Session) - return dSess.SetRoots(ctx, name, roots) -} - -func (d DoltCheckoutFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_CHECKOUT(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltCheckoutFunc) Type() sql.Type { - return sql.Int8 -} - -func (d DoltCheckoutFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltCheckoutFunc(children...) -} - -// Deprecated: please use the version in the dprocedures package -func NewDoltCheckoutFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltCheckoutFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_clean.go b/go/libraries/doltcore/sqle/dfunctions/dolt_clean.go deleted file mode 100644 index d96bf31d1d..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_clean.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2020 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" -) - -const DoltCleanFuncName = "dolt_clean" - -// Deprecated: please use the version in the dprocedures package -type DoltCleanFunc struct { - children []sql.Expression -} - -func (d DoltCleanFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return 1, err - } - return DoDoltClean(ctx, args) -} - -func DoDoltClean(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return 1, fmt.Errorf("Empty database name.") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return statusErr, err - } - - dSess := dsess.DSessFromSess(ctx.Session) - - apr, err := cli.CreateCleanArgParser().Parse(args) - if err != nil { - return 1, err - } - - // Get all the needed roots. - roots, ok := dSess.GetRoots(ctx, dbName) - if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - roots, err = actions.CleanUntracked(ctx, roots, apr.Args, apr.ContainsAll(cli.DryRunFlag)) - if err != nil { - return 1, fmt.Errorf("failed to clean; %w", err) - } - - err = dSess.SetRoots(ctx, dbName, roots) - if err != nil { - return 1, err - } - return 0, nil -} - -func (d DoltCleanFunc) Resolved() bool { - for _, child := range d.Children() { - if !child.Resolved() { - return false - } - } - return true -} - -func (d DoltCleanFunc) String() string { - childrenStrings := make([]string, len(d.children)) - - for i, child := range d.children { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_CLEAN(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltCleanFunc) Type() sql.Type { - return sql.Int8 -} - -func (d DoltCleanFunc) IsNullable() bool { - for _, child := range d.Children() { - if child.IsNullable() { - return true - } - } - return false -} - -func (d DoltCleanFunc) Children() []sql.Expression { - return d.children -} - -func (d DoltCleanFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltCleanFunc(children...) -} - -// Deprecated: please use the version in the dprocedures package -func NewDoltCleanFunc(args ...sql.Expression) (sql.Expression, error) { - return DoltCleanFunc{children: args}, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_commit.go b/go/libraries/doltcore/sqle/dfunctions/dolt_commit.go deleted file mode 100644 index bf23f23d9e..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_commit.go +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright 2020 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "errors" - "fmt" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/vitess/go/vt/proto/query" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" -) - -const DoltCommitFuncName = "dolt_commit" - -var hashType = sql.MustCreateString(query.Type_TEXT, 32, sql.Collation_ascii_bin) - -// DoltCommitFunc runs a `dolt commit` in the SQL context, committing staged changes to head. -// Deprecated: please use the version in the dprocedures package -type DoltCommitFunc struct { - children []sql.Expression -} - -// NewDoltCommitFunc creates a new DoltCommitFunc expression whose children represents the args passed in DOLT_COMMIT. -// Deprecated: please use the version in the dprocedures package -func NewDoltCommitFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltCommitFunc{children: args}, nil -} - -func (d DoltCommitFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return noConflictsOrViolations, err - } - return DoDoltCommit(ctx, args) -} - -func DoDoltCommit(ctx *sql.Context, args []string) (string, error) { - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return "", err - } - // Get the information for the sql context. - dbName := ctx.GetCurrentDatabase() - - apr, err := cli.CreateCommitArgParser().Parse(args) - if err != nil { - return "", err - } - - dSess := dsess.DSessFromSess(ctx.Session) - roots, ok := dSess.GetRoots(ctx, dbName) - if !ok { - return "", fmt.Errorf("Could not load database %s", dbName) - } - - if apr.Contains(cli.UpperCaseAllFlag) { - roots, err = actions.StageAllTables(ctx, roots) - if err != nil { - return "", fmt.Errorf(err.Error()) - } - } else if apr.Contains(cli.AllFlag) { - roots, err = actions.StageModifiedAndDeletedTables(ctx, roots) - if err != nil { - return "", fmt.Errorf(err.Error()) - } - } - - var name, email string - if authorStr, ok := apr.GetValue(cli.AuthorParam); ok { - name, email, err = cli.ParseAuthor(authorStr) - if err != nil { - return "", err - } - } else { - name = dSess.Username() - email = dSess.Email() - } - - amend := apr.Contains(cli.AmendFlag) - - msg, msgOk := apr.GetValue(cli.MessageArg) - if !msgOk { - if amend { - commit, err := dSess.GetHeadCommit(ctx, dbName) - if err != nil { - return "", err - } - commitMeta, err := commit.GetCommitMeta(ctx) - if err != nil { - return "", err - } - msg = commitMeta.Description - } else { - return "", fmt.Errorf("Must provide commit message.") - } - } - - t := ctx.QueryTime() - if commitTimeStr, ok := apr.GetValue(cli.DateParam); ok { - var err error - t, err = cli.ParseDate(commitTimeStr) - - if err != nil { - return "", fmt.Errorf(err.Error()) - } - } - - pendingCommit, err := dSess.NewPendingCommit(ctx, dbName, roots, actions.CommitStagedProps{ - Message: msg, - Date: t, - AllowEmpty: apr.Contains(cli.AllowEmptyFlag), - Amend: amend, - Force: apr.Contains(cli.ForceFlag), - Name: name, - Email: email, - }) - if err != nil { - return "", err - } - - // Nothing to commit, and we didn't pass --allowEmpty - if pendingCommit == nil { - return "", errors.New("nothing to commit") - } - - newCommit, err := dSess.DoltCommit(ctx, dbName, dSess.GetTransaction(), pendingCommit) - if err != nil { - return "", err - } - - h, err := newCommit.HashOf() - if err != nil { - return "", err - } - - return h.String(), nil -} - -func getDoltArgs(ctx *sql.Context, row sql.Row, children []sql.Expression) ([]string, error) { - args := make([]string, len(children)) - for i := range children { - childVal, err := children[i].Eval(ctx, row) - - if err != nil { - return nil, err - } - - text, err := sql.Text.Convert(childVal) - - if err != nil { - return nil, err - } - - args[i] = text.(string) - } - - return args, nil -} - -func (d DoltCommitFunc) String() string { - childrenStrings := make([]string, len(d.children)) - - for _, child := range d.children { - childrenStrings = append(childrenStrings, child.String()) - } - return fmt.Sprintf("commit_hash") -} - -func (d DoltCommitFunc) Type() sql.Type { - return sql.Text -} - -func (d DoltCommitFunc) IsNullable() bool { - return false -} - -func (d DoltCommitFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltCommitFunc(children...) -} - -func (d DoltCommitFunc) Resolved() bool { - for _, child := range d.Children() { - if !child.Resolved() { - return false - } - } - return true -} - -func (d DoltCommitFunc) Children() []sql.Expression { - return d.children -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_fetch.go b/go/libraries/doltcore/sqle/dfunctions/dolt_fetch.go deleted file mode 100644 index fd78469bc7..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_fetch.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/ref" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" -) - -const DoltFetchFuncName = "dolt_fetch" - -const ( - cmdFailure = 0 - cmdSuccess = 1 -) - -// Deprecated: please use the version in the dprocedures package -type DoltFetchFunc struct { - expression.NaryExpression -} - -// NewFetchFunc creates a new FetchFunc expression. -// Deprecated: please use the version in the dprocedures package -func NewFetchFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltFetchFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -func (d DoltFetchFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_FETCH(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltFetchFunc) Type() sql.Type { - return sql.Boolean -} - -func (d DoltFetchFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewFetchFunc(children...) -} - -func (d DoltFetchFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return cmdFailure, err - } - return DoDoltFetch(ctx, args) -} - -func DoDoltFetch(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return cmdFailure, fmt.Errorf("empty database name") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return cmdFailure, err - } - - sess := dsess.DSessFromSess(ctx.Session) - dbData, ok := sess.GetDbData(ctx, dbName) - if !ok { - return cmdFailure, fmt.Errorf("Could not load database %s", dbName) - } - - apr, err := cli.CreateFetchArgParser().Parse(args) - if err != nil { - return cmdFailure, err - } - - remote, refSpecs, err := env.NewFetchOpts(apr.Args, dbData.Rsr) - if err != nil { - return cmdFailure, err - } - - updateMode := ref.UpdateMode{Force: apr.Contains(cli.ForceFlag)} - - srcDB, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, remote, false) - if err != nil { - return 1, err - } - - err = actions.FetchRefSpecs(ctx, dbData, srcDB, refSpecs, remote, updateMode, runProgFuncs, stopProgFuncs) - if err != nil { - return cmdFailure, fmt.Errorf("fetch failed: %w", err) - } - return cmdSuccess, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_merge.go b/go/libraries/doltcore/sqle/dfunctions/dolt_merge.go deleted file mode 100644 index e52fef4475..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_merge.go +++ /dev/null @@ -1,487 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "errors" - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/merge" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/libraries/doltcore/table/editor" - "github.com/dolthub/dolt/go/libraries/utils/argparser" -) - -// Deprecated: please use the version in the dprocedures package -func NewDoltMergeFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltMergeFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -const DoltMergeFuncName = "dolt_merge" - -// Deprecated: please use the version in the dprocedures package -type DoltMergeFunc struct { - expression.NaryExpression -} - -const DoltMergeWarningCode int = 1105 // Since this our own custom warning we'll use 1105, the code for an unknown error - -const ( - noConflictsOrViolations int = 0 - hasConflictsOrViolations int = 1 -) - -const ( - threeWayMerge = 0 - fastForwardMerge = 1 -) - -func (d DoltMergeFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return noConflictsOrViolations, err - } - hasConflicts, _, err := DoDoltMerge(ctx, args) - return hasConflicts, err -} - -// DoDoltMerge returns has_conflicts and fast_forward status -func DoDoltMerge(ctx *sql.Context, args []string) (int, int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("Empty database name.") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - sess := dsess.DSessFromSess(ctx.Session) - - apr, err := cli.CreateMergeArgParser().Parse(args) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - if apr.ContainsAll(cli.SquashParam, cli.NoFFParam) { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("error: Flags '--%s' and '--%s' cannot be used together.\n", cli.SquashParam, cli.NoFFParam) - } - - ws, err := sess.WorkingSet(ctx, dbName) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - roots, ok := sess.GetRoots(ctx, dbName) - if !ok { - return noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) - } - - if apr.Contains(cli.AbortParam) { - if !ws.MergeActive() { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("fatal: There is no merge to abort") - } - - ws, err = abortMerge(ctx, ws, roots) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - err := sess.SetWorkingSet(ctx, dbName, ws) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - err = sess.CommitWorkingSet(ctx, dbName, sess.GetTransaction()) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - return noConflictsOrViolations, threeWayMerge, nil - } - - branchName := apr.Arg(0) - - mergeSpec, err := createMergeSpec(ctx, sess, dbName, apr, branchName) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - dbData, ok := sess.GetDbData(ctx, dbName) - if !ok { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("Could not load database %s", dbName) - } - msg := fmt.Sprintf("Merge branch '%s' into %s", branchName, dbData.Rsr.CWBHeadRef().GetPath()) - if userMsg, mOk := apr.GetValue(cli.MessageArg); mOk { - msg = userMsg - } - - ws, conflicts, fastForward, err := performMerge(ctx, sess, roots, ws, dbName, mergeSpec, apr.Contains(cli.NoCommitFlag), msg) - if err != nil || conflicts != 0 || fastForward != 0 { - return conflicts, fastForward, err - } - - return conflicts, fastForward, nil -} - -// performMerge encapsulates server merge logic, switching between -// fast-forward, no fast-forward, merge commit, and merging into working set. -// Returns a new WorkingSet, whether there were merge conflicts, and whether a -// fast-forward was performed. This commits the working set if merge is successful and -// 'no-commit' flag is not defined. -// TODO FF merging commit with constraint violations requires `constraint verify` -func performMerge(ctx *sql.Context, sess *dsess.DoltSession, roots doltdb.Roots, ws *doltdb.WorkingSet, dbName string, spec *merge.MergeSpec, noCommit bool, msg string) (*doltdb.WorkingSet, int, int, error) { - // todo: allow merges even when an existing merge is uncommitted - if ws.MergeActive() { - return ws, noConflictsOrViolations, threeWayMerge, doltdb.ErrMergeActive - } - - err := checkForUncommittedChanges(ctx, roots.Working, roots.Head) - if err != nil { - return ws, noConflictsOrViolations, threeWayMerge, err - } - - dbData, ok := sess.GetDbData(ctx, dbName) - if !ok { - return ws, noConflictsOrViolations, threeWayMerge, fmt.Errorf("failed to get dbData") - } - - canFF, err := spec.HeadC.CanFastForwardTo(ctx, spec.MergeC) - if err != nil { - switch err { - case doltdb.ErrIsAhead, doltdb.ErrUpToDate: - ctx.Warn(DoltMergeWarningCode, err.Error()) - default: - return ws, noConflictsOrViolations, threeWayMerge, err - } - } - - if canFF { - if spec.Noff { - ws, err = executeNoFFMerge(ctx, sess, spec, dbName, ws, dbData) - if err == doltdb.ErrUnresolvedConflictsOrViolations { - // if there are unresolved conflicts, write the resulting working set back to the session and return an - // error message - wsErr := sess.SetWorkingSet(ctx, dbName, ws) - if wsErr != nil { - return ws, hasConflictsOrViolations, threeWayMerge, wsErr - } - - ctx.Warn(DoltMergeWarningCode, err.Error()) - - return ws, hasConflictsOrViolations, threeWayMerge, nil - } - return ws, noConflictsOrViolations, fastForwardMerge, err - } - - ws, err = executeFFMerge(ctx, dbName, spec.Squash, ws, dbData, spec.MergeC) - return ws, noConflictsOrViolations, fastForwardMerge, err - } - - dbState, ok, err := sess.LookupDbState(ctx, dbName) - if err != nil { - return ws, noConflictsOrViolations, threeWayMerge, err - } else if !ok { - return ws, noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) - } - - ws, err = executeMerge(ctx, spec.Squash, spec.HeadC, spec.MergeC, spec.MergeCSpecStr, ws, dbState.EditOpts()) - if err == doltdb.ErrUnresolvedConflictsOrViolations { - // if there are unresolved conflicts, write the resulting working set back to the session and return an - // error message - wsErr := sess.SetWorkingSet(ctx, dbName, ws) - if wsErr != nil { - return ws, hasConflictsOrViolations, threeWayMerge, wsErr - } - - ctx.Warn(DoltMergeWarningCode, err.Error()) - - return ws, hasConflictsOrViolations, threeWayMerge, nil - } else if err != nil { - return ws, noConflictsOrViolations, threeWayMerge, err - } - - err = sess.SetWorkingSet(ctx, dbName, ws) - if err != nil { - return ws, noConflictsOrViolations, threeWayMerge, err - } - - if !noCommit { - author := fmt.Sprintf("%s <%s>", spec.Name, spec.Email) - _, err = DoDoltCommit(ctx, []string{"-m", msg, "--author", author}) - if err != nil { - return ws, noConflictsOrViolations, threeWayMerge, fmt.Errorf("dolt_commit failed") - } - } - - return ws, noConflictsOrViolations, threeWayMerge, nil -} - -func abortMerge(ctx *sql.Context, workingSet *doltdb.WorkingSet, roots doltdb.Roots) (*doltdb.WorkingSet, error) { - tbls, err := doltdb.UnionTableNames(ctx, roots.Working, roots.Staged, roots.Head) - if err != nil { - return nil, err - } - - roots, err = actions.MoveTablesFromHeadToWorking(ctx, roots, tbls) - if err != nil { - return nil, err - } - - // TODO: this doesn't seem right, it sets the root that we already edited above - workingSet = workingSet.AbortMerge() - return workingSet, nil -} - -func executeMerge(ctx *sql.Context, squash bool, head, cm *doltdb.Commit, cmSpec string, ws *doltdb.WorkingSet, opts editor.Options) (*doltdb.WorkingSet, error) { - mergeRoot, mergeStats, err := merge.MergeCommits(ctx, head, cm, opts) - - if err != nil { - switch err { - case doltdb.ErrUpToDate: - return nil, errors.New("Already up to date.") - case merge.ErrFastForward: - panic("fast forward merge") - default: - return nil, err - } - } - - return mergeRootToWorking(squash, ws, mergeRoot, cm, cmSpec, mergeStats) -} - -func executeFFMerge(ctx *sql.Context, dbName string, squash bool, ws *doltdb.WorkingSet, dbData env.DbData, cm2 *doltdb.Commit) (*doltdb.WorkingSet, error) { - rv, err := cm2.GetRootValue(ctx) - if err != nil { - return ws, err - } - - // TODO: This is all incredibly suspect, needs to be replaced with library code that is functional instead of - // altering global state - if !squash { - err = dbData.Ddb.FastForward(ctx, dbData.Rsr.CWBHeadRef(), cm2) - if err != nil { - return ws, err - } - } - - ws = ws.WithWorkingRoot(rv).WithStagedRoot(rv) - - // We need to assign the working set to the session but ensure that its state is not labeled as dirty (ffs are clean - // merges). Hence, we go ahead and commit the working set to the transaction. - sess := dsess.DSessFromSess(ctx.Session) - - err = sess.SetWorkingSet(ctx, dbName, ws) - if err != nil { - return ws, err - } - - // We only fully commit our transaction when we are not squashing. - if !squash { - err = sess.CommitWorkingSet(ctx, dbName, sess.GetTransaction()) - if err != nil { - return ws, err - } - } - - return ws, nil -} - -func executeNoFFMerge( - ctx *sql.Context, - dSess *dsess.DoltSession, - spec *merge.MergeSpec, - dbName string, - ws *doltdb.WorkingSet, - dbData env.DbData, -) (*doltdb.WorkingSet, error) { - mergeRoot, err := spec.MergeC.GetRootValue(ctx) - if err != nil { - return nil, err - } - - ws, err = mergeRootToWorking(false, ws, mergeRoot, spec.MergeC, spec.MergeCSpecStr, map[string]*merge.MergeStats{}) - if err != nil { - // This error is recoverable, so we return a working set value along with the error - return ws, err - } - - // Save our work so far in the session, as it will be referenced by the commit call below (badly in need of a - // refactoring) - err = dSess.SetWorkingSet(ctx, dbName, ws) - if err != nil { - return nil, err - } - - // The roots need refreshing after the above - roots, _ := dSess.GetRoots(ctx, dbName) - - pendingCommit, err := dSess.NewPendingCommit(ctx, dbName, roots, actions.CommitStagedProps{ - Message: spec.Msg, - Date: spec.Date, - AllowEmpty: spec.AllowEmpty, - Force: spec.Force, - Name: spec.Name, - Email: spec.Email, - }) - if err != nil { - return nil, err - } - - if pendingCommit == nil { - return nil, errors.New("nothing to commit") - } - - _, err = dSess.DoltCommit(ctx, dbName, dSess.GetTransaction(), pendingCommit) - if err != nil { - return nil, err - } - - return ws, nil -} - -func createMergeSpec(ctx *sql.Context, sess *dsess.DoltSession, dbName string, apr *argparser.ArgParseResults, commitSpecStr string) (*merge.MergeSpec, error) { - ddb, ok := sess.GetDoltDB(ctx, dbName) - - dbData, ok := sess.GetDbData(ctx, dbName) - - msg, ok := apr.GetValue(cli.MessageArg) - if !ok { - // TODO probably change, but we can't open editor so it'll have to be automated - msg = "automatic SQL merge" - } - - var err error - var name, email string - if authorStr, ok := apr.GetValue(cli.AuthorParam); ok { - name, email, err = cli.ParseAuthor(authorStr) - if err != nil { - return nil, err - } - } else { - name = sess.Username() - email = sess.Email() - } - - t := ctx.QueryTime() - if commitTimeStr, ok := apr.GetValue(cli.DateParam); ok { - t, err = cli.ParseDate(commitTimeStr) - if err != nil { - return nil, err - } - } - - roots, ok := sess.GetRoots(ctx, dbName) - if !ok { - return nil, sql.ErrDatabaseNotFound.New(dbName) - } - - if apr.Contains(cli.NoCommitFlag) && apr.Contains(cli.CommitFlag) { - return nil, errors.New("cannot define both 'commit' and 'no-commit' flags at the same time") - } - mergeSpec, err := merge.NewMergeSpec(ctx, dbData.Rsr, ddb, roots, name, email, msg, commitSpecStr, apr.Contains(cli.SquashParam), apr.Contains(cli.NoFFParam), apr.Contains(cli.ForceFlag), apr.Contains(cli.NoCommitFlag), apr.Contains(cli.NoEditFlag), t) - if err != nil { - return nil, err - } - return mergeSpec, nil -} - -// TODO: this copied from commands/merge.go because the latter isn't reusable. Fix that. -func mergeRootToWorking( - squash bool, - ws *doltdb.WorkingSet, - mergedRoot *doltdb.RootValue, - cm2 *doltdb.Commit, - cm2Spec string, - mergeStats map[string]*merge.MergeStats, -) (*doltdb.WorkingSet, error) { - - workingRoot := mergedRoot - if !squash { - ws = ws.StartMerge(cm2, cm2Spec) - } - - ws = ws.WithWorkingRoot(workingRoot).WithStagedRoot(workingRoot) - if checkForConflicts(mergeStats) || checkForViolations(mergeStats) { - // this error is recoverable in-session, so we return the new ws along with the error - return ws, doltdb.ErrUnresolvedConflictsOrViolations - } - - return ws, nil -} - -func checkForUncommittedChanges(ctx *sql.Context, root *doltdb.RootValue, headRoot *doltdb.RootValue) error { - rh, err := root.HashOf() - - if err != nil { - return err - } - - hrh, err := headRoot.HashOf() - - if err != nil { - return err - } - - if rh != hrh { - return ErrUncommittedChanges.New() - } - return nil -} - -func checkForConflicts(tblToStats map[string]*merge.MergeStats) bool { - for _, stats := range tblToStats { - if stats.Operation == merge.TableModified && stats.Conflicts > 0 { - return true - } - } - - return false -} - -func checkForViolations(tblToStats map[string]*merge.MergeStats) bool { - for _, stats := range tblToStats { - if stats.ConstraintViolations > 0 { - return true - } - } - return false -} - -func (d DoltMergeFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_MERGE(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltMergeFunc) Type() sql.Type { - return sql.Boolean -} - -func (d DoltMergeFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltMergeFunc(children...) -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_pull.go b/go/libraries/doltcore/sqle/dfunctions/dolt_pull.go deleted file mode 100644 index 9a28195149..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_pull.go +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "context" - "errors" - "fmt" - "strings" - "sync" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/ref" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/store/datas/pull" -) - -const DoltPullFuncName = "dolt_pull" - -// Deprecated: please use the version in the dprocedures package -type DoltPullFunc struct { - expression.NaryExpression -} - -// NewPullFunc creates a new PullFunc expression. -// Deprecated: please use the version in the dprocedures package -func NewPullFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltPullFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -func (d DoltPullFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_PULL(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltPullFunc) Type() sql.Type { - return sql.Boolean -} - -func (d DoltPullFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewPullFunc(children...) -} - -func (d DoltPullFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return noConflictsOrViolations, err - } - conflicts, _, err := DoDoltPull(ctx, args) - return conflicts, err -} - -// DoDoltPull returns conflicts, fast_forward statuses -func DoDoltPull(ctx *sql.Context, args []string) (int, int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("empty database name.") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - sess := dsess.DSessFromSess(ctx.Session) - dbData, ok := sess.GetDbData(ctx, dbName) - if !ok { - return noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) - } - - apr, err := cli.CreatePullArgParser().Parse(args) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - if apr.NArg() > 2 { - return noConflictsOrViolations, threeWayMerge, actions.ErrInvalidPullArgs - } - - var remoteName, remoteRefName string - if apr.NArg() == 1 { - remoteName = apr.Arg(0) - } else if apr.NArg() == 2 { - remoteName = apr.Arg(0) - remoteRefName = apr.Arg(1) - } - - pullSpec, err := env.NewPullSpec(ctx, dbData.Rsr, remoteName, remoteRefName, apr.Contains(cli.SquashParam), apr.Contains(cli.NoFFParam), apr.Contains(cli.NoCommitFlag), apr.Contains(cli.NoEditFlag), apr.Contains(cli.ForceFlag), apr.NArg() == 1) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - srcDB, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, pullSpec.Remote, false) - if err != nil { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("failed to get remote db; %w", err) - } - - ws, err := sess.WorkingSet(ctx, dbName) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - // Fetch all references - branchRefs, err := srcDB.GetHeadRefs(ctx) - if err != nil { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("%w: %s", env.ErrFailedToReadDb, err.Error()) - } - - _, hasBranch, err := srcDB.HasBranch(ctx, pullSpec.Branch.GetPath()) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - if !hasBranch { - return noConflictsOrViolations, threeWayMerge, - fmt.Errorf("branch %q not found on remote", pullSpec.Branch.GetPath()) - } - - var conflicts int - var fastForward int - for _, refSpec := range pullSpec.RefSpecs { - rsSeen := false // track invalid refSpecs - for _, branchRef := range branchRefs { - remoteTrackRef := refSpec.DestRef(branchRef) - - if remoteTrackRef == nil { - continue - } - - rsSeen = true - tmpDir, err := dbData.Rsw.TempTableFilesDir() - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - // todo: can we pass nil for either of the channels? - srcDBCommit, err := actions.FetchRemoteBranch(ctx, tmpDir, pullSpec.Remote, srcDB, dbData.Ddb, branchRef, nil, nil) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - // TODO: this could be replaced with a canFF check to test for error - err = dbData.Ddb.FastForward(ctx, remoteTrackRef, srcDBCommit) - if err != nil { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("fetch failed; %w", err) - } - - // Only merge iff branch is current branch and there is an upstream set (pullSpec.Branch is set to nil if there is no upstream) - if branchRef != pullSpec.Branch { - continue - } - - roots, ok := sess.GetRoots(ctx, dbName) - if !ok { - return noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) - } - - mergeSpec, err := createMergeSpec(ctx, sess, dbName, apr, remoteTrackRef.String()) - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - - msg := fmt.Sprintf("Merge branch '%s' of %s into %s", pullSpec.Branch.GetPath(), pullSpec.Remote.Url, dbData.Rsr.CWBHeadRef().GetPath()) - ws, conflicts, fastForward, err = performMerge(ctx, sess, roots, ws, dbName, mergeSpec, apr.Contains(cli.NoCommitFlag), msg) - if err != nil && !errors.Is(doltdb.ErrUpToDate, err) { - return conflicts, fastForward, err - } - - err = sess.SetWorkingSet(ctx, dbName, ws) - if err != nil { - return conflicts, fastForward, err - } - } - if !rsSeen { - return noConflictsOrViolations, threeWayMerge, fmt.Errorf("%w: '%s'", ref.ErrInvalidRefSpec, refSpec.GetRemRefToLocal()) - } - } - - tmpDir, err := dbData.Rsw.TempTableFilesDir() - if err != nil { - return noConflictsOrViolations, threeWayMerge, err - } - err = actions.FetchFollowTags(ctx, tmpDir, srcDB, dbData.Ddb, runProgFuncs, stopProgFuncs) - if err != nil { - return conflicts, fastForward, err - } - - return conflicts, fastForward, nil -} - -func pullerProgFunc(ctx context.Context, statsCh <-chan pull.Stats) { - for { - if ctx.Err() != nil { - return - } - select { - case <-ctx.Done(): - return - case <-statsCh: - default: - } - } -} - -func progFunc(ctx context.Context, progChan <-chan pull.PullProgress) { - for { - if ctx.Err() != nil { - return - } - select { - case <-ctx.Done(): - return - case <-progChan: - default: - } - } -} - -func runProgFuncs(ctx context.Context) (*sync.WaitGroup, chan pull.PullProgress, chan pull.Stats) { - statsCh := make(chan pull.Stats) - progChan := make(chan pull.PullProgress) - wg := &sync.WaitGroup{} - - wg.Add(1) - go func() { - defer wg.Done() - progFunc(ctx, progChan) - }() - - wg.Add(1) - go func() { - defer wg.Done() - pullerProgFunc(ctx, statsCh) - }() - - return wg, progChan, statsCh -} - -func stopProgFuncs(cancel context.CancelFunc, wg *sync.WaitGroup, progChan chan pull.PullProgress, statsCh chan pull.Stats) { - cancel() - close(progChan) - close(statsCh) - wg.Wait() -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_push.go b/go/libraries/doltcore/sqle/dfunctions/dolt_push.go deleted file mode 100644 index 2a4ef333b6..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_push.go +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strconv" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/env" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/store/datas" -) - -const DoltPushFuncName = "dolt_push" - -// Deprecated: please use the version in the dprocedures package -type DoltPushFunc struct { - expression.NaryExpression -} - -// NewPushFunc creates a new PushFunc expression. -// Deprecated: please use the version in the dprocedures package -func NewPushFunc(args ...sql.Expression) (sql.Expression, error) { - return &DoltPushFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -func (d DoltPushFunc) String() string { - childrenStrings := make([]string, len(d.Children())) - - for i, child := range d.Children() { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_PUSH(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltPushFunc) Type() sql.Type { - return sql.Boolean -} - -func (d DoltPushFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewPushFunc(children...) -} - -func (d DoltPushFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return cmdFailure, err - } - return DoDoltPush(ctx, args) -} - -func DoDoltPush(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return cmdFailure, fmt.Errorf("empty database name") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return cmdFailure, err - } - - sess := dsess.DSessFromSess(ctx.Session) - dbData, ok := sess.GetDbData(ctx, dbName) - - if !ok { - return cmdFailure, fmt.Errorf("could not load database %s", dbName) - } - - apr, err := cli.CreatePushArgParser().Parse(args) - if err != nil { - return cmdFailure, err - } - - autoSetUpRemote := loadConfig(ctx).GetStringOrDefault(env.PushAutoSetupRemote, "false") - pushAutoSetUpRemote, err := strconv.ParseBool(autoSetUpRemote) - if err != nil { - return cmdFailure, err - } - - opts, err := env.NewPushOpts(ctx, apr, dbData.Rsr, dbData.Ddb, apr.Contains(cli.ForceFlag), apr.Contains(cli.SetUpstreamFlag), pushAutoSetUpRemote) - if err != nil { - return cmdFailure, err - } - remoteDB, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, opts.Remote, true) - if err != nil { - return 1, actions.HandleInitRemoteStorageClientErr(opts.Remote.Name, opts.Remote.Url, err) - } - - tmpDir, err := dbData.Rsw.TempTableFilesDir() - if err != nil { - return cmdFailure, err - } - err = actions.DoPush(ctx, dbData.Rsr, dbData.Rsw, dbData.Ddb, remoteDB, tmpDir, opts, runProgFuncs, stopProgFuncs) - if err != nil { - switch err { - case doltdb.ErrUpToDate: - return cmdSuccess, nil - case datas.ErrMergeNeeded: - return cmdFailure, fmt.Errorf("%w; the tip of your current branch is behind its remote counterpart", err) - default: - return cmdFailure, err - } - } - // TODO : set upstream should be persisted outside of session - return cmdSuccess, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/dolt_reset.go b/go/libraries/doltcore/sqle/dfunctions/dolt_reset.go deleted file mode 100644 index 5e340adcf6..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/dolt_reset.go +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2020 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" -) - -const DoltResetFuncName = "dolt_reset" - -// Deprecated: please use the version in the dprocedures package -type DoltResetFunc struct { - children []sql.Expression -} - -func (d DoltResetFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, d.Children()) - if err != nil { - return 1, err - } - return DoDoltReset(ctx, args) -} - -func DoDoltReset(ctx *sql.Context, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - - if len(dbName) == 0 { - return 1, fmt.Errorf("Empty database name.") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return 1, err - } - - dSess := dsess.DSessFromSess(ctx.Session) - dbData, ok := dSess.GetDbData(ctx, dbName) - - if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - apr, err := cli.CreateResetArgParser().Parse(args) - if err != nil { - return 1, err - } - - // Check if problems with args first. - if apr.ContainsAll(cli.HardResetParam, cli.SoftResetParam) { - return 1, fmt.Errorf("error: --%s and --%s are mutually exclusive options.", cli.HardResetParam, cli.SoftResetParam) - } - - provider := dSess.Provider() - db, err := provider.Database(ctx, dbName) - if err != nil { - return 1, err - } - - // Disallow manipulating any roots for read-only databases – changing the branch - // HEAD would allow changing data, and working set and index shouldn't ever have - // any contents for a read-only database. - if rodb, ok := db.(sql.ReadOnlyDatabase); ok { - if rodb.IsReadOnly() { - return 1, fmt.Errorf("unable to reset HEAD in read-only databases") - } - } - - // Get all the needed roots. - roots, ok := dSess.GetRoots(ctx, dbName) - if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - if apr.Contains(cli.HardResetParam) { - // Get the commitSpec for the branch if it exists - arg := "" - if apr.NArg() > 1 { - return 1, fmt.Errorf("--hard supports at most one additional param") - } else if apr.NArg() == 1 { - arg = apr.Arg(0) - } - - var newHead *doltdb.Commit - newHead, roots, err = actions.ResetHardTables(ctx, dbData, arg, roots) - if err != nil { - return 1, err - } - - // TODO: this overrides the transaction setting, needs to happen at commit, not here - if newHead != nil { - if err := dbData.Ddb.SetHeadToCommit(ctx, dbData.Rsr.CWBHeadRef(), newHead); err != nil { - return 1, err - } - } - - ws, err := dSess.WorkingSet(ctx, dbName) - if err != nil { - return 1, err - } - err = dSess.SetWorkingSet(ctx, dbName, ws.WithWorkingRoot(roots.Working).WithStagedRoot(roots.Staged).ClearMerge()) - if err != nil { - return 1, err - } - } else { - roots, err = actions.ResetSoftTables(ctx, dbData, apr, roots) - if err != nil { - return 1, err - } - - err = dSess.SetRoots(ctx, dbName, roots) - if err != nil { - return 1, err - } - } - - return 0, nil -} - -func (d DoltResetFunc) Resolved() bool { - for _, child := range d.Children() { - if !child.Resolved() { - return false - } - } - return true -} - -func (d DoltResetFunc) String() string { - childrenStrings := make([]string, len(d.children)) - - for i, child := range d.children { - childrenStrings[i] = child.String() - } - - return fmt.Sprintf("DOLT_RESET(%s)", strings.Join(childrenStrings, ",")) -} - -func (d DoltResetFunc) Type() sql.Type { - return sql.Int8 -} - -func (d DoltResetFunc) IsNullable() bool { - for _, child := range d.Children() { - if child.IsNullable() { - return true - } - } - return false -} - -func (d DoltResetFunc) Children() []sql.Expression { - return d.children -} - -func (d DoltResetFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewDoltResetFunc(children...) -} - -// Deprecated: please use the version in the dprocedures package -func NewDoltResetFunc(args ...sql.Expression) (sql.Expression, error) { - return DoltResetFunc{children: args}, nil -} diff --git a/go/libraries/doltcore/sqle/dfunctions/init.go b/go/libraries/doltcore/sqle/dfunctions/init.go index 9aa8e85466..d6b03f55f0 100644 --- a/go/libraries/doltcore/sqle/dfunctions/init.go +++ b/go/libraries/doltcore/sqle/dfunctions/init.go @@ -18,25 +18,10 @@ import "github.com/dolthub/go-mysql-server/sql" var DoltFunctions = []sql.Function{ sql.Function1{Name: HashOfFuncName, Fn: NewHashOf}, - sql.FunctionN{Name: CommitFuncName, Fn: NewCommitFunc}, - sql.FunctionN{Name: MergeFuncName, Fn: NewMergeFunc}, sql.Function0{Name: VersionFuncName, Fn: NewVersion}, sql.Function0{Name: StorageFormatFuncName, Fn: NewStorageFormat}, - sql.FunctionN{Name: DoltCommitFuncName, Fn: NewDoltCommitFunc}, - sql.FunctionN{Name: DoltAddFuncName, Fn: NewDoltAddFunc}, - sql.FunctionN{Name: DoltCleanFuncName, Fn: NewDoltCleanFunc}, - sql.FunctionN{Name: DoltResetFuncName, Fn: NewDoltResetFunc}, - sql.FunctionN{Name: DoltCheckoutFuncName, Fn: NewDoltCheckoutFunc}, - sql.FunctionN{Name: DoltMergeFuncName, Fn: NewDoltMergeFunc}, sql.Function0{Name: ActiveBranchFuncName, Fn: NewActiveBranchFunc}, sql.Function2{Name: DoltMergeBaseFuncName, Fn: NewMergeBase}, - sql.FunctionN{Name: ConstraintsVerifyFuncName, Fn: NewConstraintsVerifyFunc}, - sql.FunctionN{Name: RevertFuncName, Fn: NewRevertFunc}, - sql.FunctionN{Name: DoltPullFuncName, Fn: NewPullFunc}, - sql.FunctionN{Name: DoltFetchFuncName, Fn: NewFetchFunc}, - sql.FunctionN{Name: DoltPushFuncName, Fn: NewPushFunc}, - sql.FunctionN{Name: DoltBranchFuncName, Fn: NewDoltBranchFunc}, - sql.FunctionN{Name: DoltBackupFuncName, Fn: NewDoltBackupFunc}, } // DolthubApiFunctions are the DoltFunctions that get exposed to Dolthub Api. diff --git a/go/libraries/doltcore/sqle/dfunctions/merge.go b/go/libraries/doltcore/sqle/dfunctions/merge.go deleted file mode 100644 index b86241a8ba..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/merge.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2020 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - "strings" - - "github.com/dolthub/go-mysql-server/sql" - goerrors "gopkg.in/src-d/go-errors.v1" -) - -const MergeFuncName = "merge" - -var ErrUncommittedChanges = goerrors.NewKind("cannot merge with uncommitted changes") - -// Deprecated: please use the version in the dprocedures package -type MergeFunc struct { - children []sql.Expression -} - -// NewMergeFunc creates a new MergeFunc expression. -// Deprecated: please use the version in the dprocedures package -func NewMergeFunc(args ...sql.Expression) (sql.Expression, error) { - return &MergeFunc{children: args}, nil -} - -// Eval implements the Expression interface. -func (mf *MergeFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, mf.Children()) - if err != nil { - return noConflictsOrViolations, err - } - hasConflicts, _, err := DoDoltMerge(ctx, args) - return hasConflicts, err -} - -// String implements the Stringer interface. -func (mf *MergeFunc) String() string { - childrenStrings := make([]string, len(mf.children)) - - for i, child := range mf.children { - childrenStrings[i] = child.String() - } - return fmt.Sprintf("Merge(%s)", strings.Join(childrenStrings, ",")) -} - -// IsNullable implements the Expression interface. -func (mf *MergeFunc) IsNullable() bool { - return false -} - -func (mf *MergeFunc) Resolved() bool { - for _, child := range mf.Children() { - if !child.Resolved() { - return false - } - } - return true -} - -func (mf *MergeFunc) Children() []sql.Expression { - return mf.children -} - -// WithChildren implements the Expression interface. -func (mf *MergeFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewMergeFunc(children...) -} - -// Type implements the Expression interface. -func (mf *MergeFunc) Type() sql.Type { - return sql.Text -} diff --git a/go/libraries/doltcore/sqle/dfunctions/revert.go b/go/libraries/doltcore/sqle/dfunctions/revert.go deleted file mode 100644 index 5831414d31..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/revert.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/merge" - "github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" -) - -const ( - RevertFuncName = "dolt_revert" -) - -// RevertFunc represents the dolt function "dolt revert". -// Deprecated: please use the version in the dprocedures package -type RevertFunc struct { - expression.NaryExpression -} - -var _ sql.Expression = (*RevertFunc)(nil) - -// NewRevertFunc creates a new RevertFunc expression that reverts commits. -// Deprecated: please use the version in the dprocedures package -func NewRevertFunc(args ...sql.Expression) (sql.Expression, error) { - return &RevertFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -// Eval implements the Expression interface. -func (r *RevertFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, r.ChildExpressions) - if err != nil { - return 1, err - } - return DoDoltRevert(ctx, row, args) -} - -func DoDoltRevert(ctx *sql.Context, row sql.Row, args []string) (int, error) { - dbName := ctx.GetCurrentDatabase() - dSess := dsess.DSessFromSess(ctx.Session) - ddb, ok := dSess.GetDoltDB(ctx, dbName) - if !ok { - return 1, fmt.Errorf("dolt database could not be found") - } - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return 1, err - } - workingSet, err := dSess.WorkingSet(ctx, dbName) - if err != nil { - return 1, err - } - workingRoot := workingSet.WorkingRoot() - headCommit, err := dSess.GetHeadCommit(ctx, dbName) - if err != nil { - return 1, err - } - headRoot, err := headCommit.GetRootValue(ctx) - if err != nil { - return 1, err - } - headHash, err := headRoot.HashOf() - if err != nil { - return 1, err - } - workingHash, err := workingRoot.HashOf() - if err != nil { - return 1, err - } - if !headHash.Equal(workingHash) { - return 1, fmt.Errorf("you must commit any changes before using revert") - } - - headRef, err := dSess.CWBHeadRef(ctx, dbName) - if err != nil { - return 1, err - } - - apr, err := cli.CreateRevertArgParser().Parse(args) - if err != nil { - return 1, err - } - - commits := make([]*doltdb.Commit, apr.NArg()) - for i, revisionStr := range apr.Args { - commitSpec, err := doltdb.NewCommitSpec(revisionStr) - if err != nil { - return 1, err - } - commit, err := ddb.Resolve(ctx, commitSpec, headRef) - if err != nil { - return 1, err - } - commits[i] = commit - } - - dbState, ok, err := dSess.LookupDbState(ctx, dbName) - if err != nil { - return 1, err - } else if !ok { - return 1, fmt.Errorf("Could not load database %s", dbName) - } - - workingRoot, revertMessage, err := merge.Revert(ctx, ddb, workingRoot, headCommit, commits, dbState.EditOpts()) - if err != nil { - return 1, err - } - workingHash, err = workingRoot.HashOf() - if err != nil { - return 1, err - } - if !headHash.Equal(workingHash) { - err = dSess.SetRoot(ctx, dbName, workingRoot) - if err != nil { - return 1, err - } - stringType := typeinfo.StringDefaultType.ToSqlType() - - expressions := []sql.Expression{expression.NewLiteral("-a", stringType), expression.NewLiteral("-m", stringType), expression.NewLiteral(revertMessage, stringType)} - - author, hasAuthor := apr.GetValue(cli.AuthorParam) - if hasAuthor { - expressions = append(expressions, expression.NewLiteral("--author", stringType), expression.NewLiteral(author, stringType)) - } - - commitFunc, err := NewDoltCommitFunc(expressions...) - if err != nil { - return 1, err - } - _, err = commitFunc.Eval(ctx, row) - if err != nil { - return 1, err - } - } - return 0, nil -} - -// String implements the Stringer interface. -func (r *RevertFunc) String() string { - return fmt.Sprint("DOLT_REVERT()") -} - -// IsNullable implements the Expression interface. -func (r *RevertFunc) IsNullable() bool { - return false -} - -// Resolved implements the Expression interface. -func (r *RevertFunc) Resolved() bool { - for _, expr := range r.ChildExpressions { - if !expr.Resolved() { - return false - } - } - return true -} - -func (r *RevertFunc) Type() sql.Type { - return sql.Int8 -} - -// Children implements the Expression interface. -func (r *RevertFunc) Children() []sql.Expression { - exprs := make([]sql.Expression, len(r.ChildExpressions)) - for i := range exprs { - exprs[i] = r.ChildExpressions[i] - } - return exprs -} - -// WithChildren implements the Expression interface. -func (r *RevertFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewRevertFunc(children...) -} diff --git a/go/libraries/doltcore/sqle/dfunctions/verify_constraints.go b/go/libraries/doltcore/sqle/dfunctions/verify_constraints.go deleted file mode 100644 index f849dd2ba2..0000000000 --- a/go/libraries/doltcore/sqle/dfunctions/verify_constraints.go +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2021 Dolthub, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dfunctions - -import ( - "fmt" - - "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/go-mysql-server/sql/expression" - - "github.com/dolthub/dolt/go/cmd/dolt/cli" - "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" - "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" - "github.com/dolthub/dolt/go/libraries/doltcore/merge" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" - "github.com/dolthub/dolt/go/libraries/utils/set" -) - -const ( - ConstraintsVerifyFuncName = "constraints_verify" -) - -// ConstraintsVerifyFunc represents the sql functions "verify_constraints" -// Deprecated: please use the version in the dprocedures package -type ConstraintsVerifyFunc struct { - expression.NaryExpression -} - -var _ sql.Expression = (*ConstraintsVerifyFunc)(nil) - -// NewConstraintsVerifyFunc creates a new ConstraintsVerifyFunc expression that verifies the diff. -// Deprecated: please use the version in the dprocedures package -func NewConstraintsVerifyFunc(args ...sql.Expression) (sql.Expression, error) { - return &ConstraintsVerifyFunc{expression.NaryExpression{ChildExpressions: args}}, nil -} - -// Eval implements the Expression interface. -func (vc *ConstraintsVerifyFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { - args, err := getDoltArgs(ctx, row, vc.ChildExpressions) - if err != nil { - return nil, err - } - return DoDoltConstraintsVerify(ctx, args) -} - -func DoDoltConstraintsVerify(ctx *sql.Context, args []string) (int, error) { - if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { - return 1, err - } - dbName := ctx.GetCurrentDatabase() - dSess := dsess.DSessFromSess(ctx.Session) - workingSet, err := dSess.WorkingSet(ctx, dbName) - if err != nil { - return 1, err - } - workingRoot := workingSet.WorkingRoot() - headCommit, err := dSess.GetHeadCommit(ctx, dbName) - if err != nil { - return 1, err - } - h, err := headCommit.HashOf() - if err != nil { - return 1, err - } - - apr, err := cli.CreateVerifyConstraintsArgParser().Parse(args) - if err != nil { - return 1, err - } - - verifyAll := apr.Contains(cli.AllFlag) - outputOnly := apr.Contains(cli.OutputOnlyFlag) - - var comparingRoot *doltdb.RootValue - if verifyAll { - comparingRoot, err = doltdb.EmptyRootValue(ctx, workingRoot.VRW(), workingRoot.NodeStore()) - if err != nil { - return 1, err - } - } else { - comparingRoot, err = headCommit.GetRootValue(ctx) - if err != nil { - return 1, err - } - } - - tableSet := set.NewStrSet(nil) - for _, val := range apr.Args { - _, tableName, ok, err := workingRoot.GetTableInsensitive(ctx, val) - if err != nil { - return 1, err - } - if !ok { - return 1, sql.ErrTableNotFound.New(tableName) - } - tableSet.Add(tableName) - } - - newRoot, tablesWithViolations, err := merge.AddForeignKeyViolations(ctx, workingRoot, comparingRoot, tableSet, h) - if err != nil { - return 1, err - } - - if tablesWithViolations.Size() == 0 { - // no violations were found - return 0, nil - } - - // violations were found - - if !outputOnly { - err = dSess.SetRoot(ctx, dbName, newRoot) - if err != nil { - return 1, err - } - return 1, nil - } - - return 1, nil -} - -// String implements the Stringer interface. -func (vc *ConstraintsVerifyFunc) String() string { - return fmt.Sprint("CONSTRAINTS_VERIFY()") -} - -// IsNullable implements the Expression interface. -func (vc *ConstraintsVerifyFunc) IsNullable() bool { - return false -} - -// Resolved implements the Expression interface. -func (vc *ConstraintsVerifyFunc) Resolved() bool { - for _, expr := range vc.ChildExpressions { - if !expr.Resolved() { - return false - } - } - return true -} - -func (vc *ConstraintsVerifyFunc) Type() sql.Type { - return sql.Int8 -} - -// Children implements the Expression interface. -func (vc *ConstraintsVerifyFunc) Children() []sql.Expression { - exprs := make([]sql.Expression, len(vc.ChildExpressions)) - for i := range exprs { - exprs[i] = vc.ChildExpressions[i] - } - return exprs -} - -// WithChildren implements the Expression interface. -func (vc *ConstraintsVerifyFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) { - return NewConstraintsVerifyFunc(children...) -} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_add.go b/go/libraries/doltcore/sqle/dprocedures/dolt_add.go index 0bc7752fc6..f4615e8e5e 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_add.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_add.go @@ -15,16 +15,71 @@ package dprocedures import ( - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "fmt" + + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" "github.com/dolthub/go-mysql-server/sql" ) // doltAdd is the stored procedure version of the function `dolt_add`. func doltAdd(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltAdd(ctx, args) + res, err := doDoltAdd(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltAdd(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return 1, fmt.Errorf("Empty database name.") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return 1, err + } + + apr, err := cli.CreateAddArgParser().Parse(args) + if err != nil { + return 1, err + } + + allFlag := apr.Contains(cli.AllFlag) + + dSess := dsess.DSessFromSess(ctx.Session) + roots, ok := dSess.GetRoots(ctx, dbName) + if apr.NArg() == 0 && !allFlag { + return 1, fmt.Errorf("Nothing specified, nothing added. Maybe you wanted to say 'dolt add .'?") + } else if allFlag || apr.NArg() == 1 && apr.Arg(0) == "." { + if !ok { + return 1, fmt.Errorf("db session not found") + } + + roots, err = actions.StageAllTables(ctx, roots) + if err != nil { + return 1, err + } + + err = dSess.SetRoots(ctx, dbName, roots) + if err != nil { + return 1, err + } + } else { + roots, err = actions.StageTables(ctx, roots, apr.Args) + if err != nil { + return 1, err + } + + err = dSess.SetRoots(ctx, dbName, roots) + if err != nil { + return 1, err + } + } + + return 0, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_backup.go b/go/libraries/doltcore/sqle/dprocedures/dolt_backup.go index 3330f4b55a..a9ca427da3 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_backup.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_backup.go @@ -15,16 +15,149 @@ package dprocedures import ( + "fmt" + "strings" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/dbfactory" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/libraries/utils/filesys" + "github.com/dolthub/dolt/go/store/datas/pull" +) + +const ( + DoltBackupFuncName = "dolt_backup" + + statusOk = 1 + statusErr = 0 ) // doltBackup is the stored procedure version of the function `dolt_backup`. func doltBackup(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltBackup(ctx, args) + res, err := doDoltBackup(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltBackup(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + if len(dbName) == 0 { + return statusErr, fmt.Errorf("Empty database name.") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return statusErr, err + } + + apr, err := cli.CreateBackupArgParser().Parse(args) + if err != nil { + return statusErr, err + } + + invalidParams := []string{dbfactory.AWSCredsFileParam, dbfactory.AWSCredsProfile, dbfactory.AWSCredsTypeParam, dbfactory.AWSRegionParam} + for _, param := range invalidParams { + if apr.Contains(param) { + return statusErr, fmt.Errorf("parameter '%s' is not supported when running this command via SQL", param) + } + } + + sess := dsess.DSessFromSess(ctx.Session) + dbData, ok := sess.GetDbData(ctx, dbName) + if !ok { + return statusErr, sql.ErrDatabaseNotFound.New(dbName) + } + + var b env.Remote + switch { + case apr.NArg() == 0: + return statusErr, fmt.Errorf("listing existing backups endpoints in sql is unimplemented.") + case apr.Arg(0) == cli.AddBackupId: + return statusErr, fmt.Errorf("adding backup endpoint in sql is unimplemented.") + case apr.Arg(0) == cli.RemoveBackupId: + return statusErr, fmt.Errorf("removing backup endpoint in sql is unimplemented.") + case apr.Arg(0) == cli.RemoveBackupShortId: + return statusErr, fmt.Errorf("removing backup endpoint in sql is unimplemented.") + case apr.Arg(0) == cli.RestoreBackupId: + return statusErr, fmt.Errorf("restoring backup endpoint in sql is unimplemented.") + case apr.Arg(0) == cli.SyncBackupUrlId: + if apr.NArg() != 2 { + return statusErr, fmt.Errorf("usage: dolt_backup('sync-url', BACKUP_URL)") + } + + backupUrl := strings.TrimSpace(apr.Arg(1)) + cfg := loadConfig(ctx) + scheme, absBackupUrl, err := env.GetAbsRemoteUrl(filesys.LocalFS, cfg, backupUrl) + if err != nil { + return statusErr, fmt.Errorf("error: '%s' is not valid.", backupUrl) + } else if scheme == dbfactory.HTTPScheme || scheme == dbfactory.HTTPSScheme { + // not sure how to get the dialer so punting on this + return statusErr, fmt.Errorf("sync-url does not support http or https backup locations currently") + } + + params, err := cli.ProcessBackupArgs(apr, scheme, absBackupUrl) + if err != nil { + return statusErr, err + } + + credsFile, _ := sess.GetSessionVariable(ctx, dsess.AwsCredsFile) + credsFileStr, isStr := credsFile.(string) + if isStr && len(credsFileStr) > 0 { + params[dbfactory.AWSCredsFileParam] = credsFileStr + } + + credsProfile, err := sess.GetSessionVariable(ctx, dsess.AwsCredsProfile) + profStr, isStr := credsProfile.(string) + if isStr && len(profStr) > 0 { + params[dbfactory.AWSCredsProfile] = profStr + } + + credsRegion, err := sess.GetSessionVariable(ctx, dsess.AwsCredsRegion) + regionStr, isStr := credsRegion.(string) + if isStr && len(regionStr) > 0 { + params[dbfactory.AWSRegionParam] = regionStr + } + + b = env.NewRemote("__temp__", backupUrl, params) + + case apr.Arg(0) == cli.SyncBackupId: + if apr.NArg() != 2 { + return statusErr, fmt.Errorf("usage: dolt_backup('sync', BACKUP_NAME)") + } + + backupName := strings.TrimSpace(apr.Arg(1)) + + backups, err := dbData.Rsr.GetBackups() + if err != nil { + return statusErr, err + } + + b, ok = backups[backupName] + if !ok { + return statusErr, fmt.Errorf("error: unknown backup: '%s'; %v", backupName, backups) + } + + default: + return statusErr, fmt.Errorf("unrecognized dolt_backup parameter: %s", apr.Arg(0)) + } + + destDb, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, b, true) + if err != nil { + return statusErr, fmt.Errorf("error loading backup destination: %w", err) + } + + tmpDir, err := dbData.Rsw.TempTableFilesDir() + if err != nil { + return statusErr, err + } + err = actions.SyncRoots(ctx, dbData.Ddb, destDb, tmpDir, runProgFuncs, stopProgFuncs) + if err != nil && err != pull.ErrDBUpToDate { + return 1, fmt.Errorf("error syncing backup: %w", err) + } + return statusOk, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_branch.go b/go/libraries/doltcore/sqle/dprocedures/dolt_branch.go index 7820cf7368..12ffee7ed1 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_branch.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_branch.go @@ -15,16 +15,315 @@ package dprocedures import ( + "errors" + "fmt" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/ref" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/libraries/doltcore/sqlserver" + "github.com/dolthub/dolt/go/libraries/utils/argparser" + "github.com/dolthub/dolt/go/libraries/utils/filesys" +) + +var ( + EmptyBranchNameErr = errors.New("error: cannot branch empty string") + InvalidArgErr = errors.New("error: invalid usage") ) // doltBranch is the stored procedure version of the function `dolt_branch`. func doltBranch(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltBranch(ctx, args) + res, err := doDoltBranch(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltBranch(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return 1, fmt.Errorf("Empty database name.") + } + + apr, err := cli.CreateBranchArgParser().Parse(args) + if err != nil { + return 1, err + } + + dSess := dsess.DSessFromSess(ctx.Session) + dbData, ok := dSess.GetDbData(ctx, dbName) + if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + switch { + case apr.Contains(cli.CopyFlag): + err = copyBranch(ctx, dbData, apr) + case apr.Contains(cli.MoveFlag): + err = renameBranch(ctx, dbData, apr, dSess, dbName) + case apr.Contains(cli.DeleteFlag), apr.Contains(cli.DeleteForceFlag): + err = deleteBranches(ctx, dbData, apr, dSess, dbName) + default: + err = createNewBranch(ctx, dbData, apr) + } + + if err != nil { + return 1, err + } else { + return 0, nil + } +} + +// renameBranch takes DoltSession and database name to try accessing file system for dolt database. +// If the oldBranch being renamed is the current branch on CLI, then RepoState head will be updated with the newBranch ref. +func renameBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string) error { + if apr.NArg() != 2 { + return InvalidArgErr + } + oldBranchName, newBranchName := apr.Arg(0), apr.Arg(1) + if oldBranchName == "" || newBranchName == "" { + return EmptyBranchNameErr + } + if err := branch_control.CanDeleteBranch(ctx, oldBranchName); err != nil { + return err + } + if err := branch_control.CanCreateBranch(ctx, newBranchName); err != nil { + return err + } + force := apr.Contains(cli.ForceFlag) + + if !force { + err := validateBranchNotActiveInAnySession(ctx, oldBranchName) + if err != nil { + return err + } + } else if err := branch_control.CanDeleteBranch(ctx, newBranchName); err != nil { + // If force is enabled, we can overwrite the destination branch, so we require a permission check here, even if the + // destination branch doesn't exist. An unauthorized user could simply rerun the command without the force flag. + return err + } + + err := actions.RenameBranch(ctx, dbData, loadConfig(ctx), oldBranchName, newBranchName, force) + if err != nil { + return err + } + err = branch_control.AddAdminForContext(ctx, newBranchName) + if err != nil { + return err + } + + // The current branch on CLI can be deleted as user can be on different branch on SQL and delete it from SQL session. + // To update current head info on RepoState, we need DoltEnv to load CLI environment. + if fs, err := sess.Provider().FileSystemForDatabase(dbName); err == nil { + if repoState, err := env.LoadRepoState(fs); err == nil { + if repoState.Head.Ref.GetPath() == oldBranchName { + repoState.Head.Ref = ref.NewBranchRef(newBranchName) + repoState.Save(fs) + } + } + } + + return nil +} + +// deleteBranches takes DoltSession and database name to try accessing file system for dolt database. +// If the database is not session state db and the branch being deleted is the current branch on CLI, it will update +// the RepoState to set head as empty branchRef. +func deleteBranches(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults, sess *dsess.DoltSession, dbName string) error { + if apr.NArg() == 0 { + return InvalidArgErr + } + + // The current branch on CLI can be deleted as user can be on different branch on SQL and delete it from SQL session. + // To update current head info on RepoState, we need DoltEnv to load CLI environment. + var rs *env.RepoState + var headOnCLI string + fs, err := sess.Provider().FileSystemForDatabase(dbName) + if err == nil { + if repoState, err := env.LoadRepoState(fs); err == nil { + rs = repoState + headOnCLI = repoState.Head.Ref.GetPath() + } + } + + // Verify that we can delete all branches before continuing + for _, branchName := range apr.Args { + if err = branch_control.CanDeleteBranch(ctx, branchName); err != nil { + return err + } + } + + var updateFS = false + for _, branchName := range apr.Args { + if len(branchName) == 0 { + return EmptyBranchNameErr + } + force := apr.Contains(cli.DeleteForceFlag) || apr.Contains(cli.ForceFlag) + + if !force { + err = validateBranchNotActiveInAnySession(ctx, branchName) + if err != nil { + return err + } + } + err = actions.DeleteBranch(ctx, dbData, loadConfig(ctx), branchName, actions.DeleteOptions{ + Force: force, + }) + if err != nil { + return err + } + if headOnCLI == branchName { + updateFS = true + } + } + + if fs != nil && updateFS { + rs.Head.Ref = ref.NewBranchRef("") + rs.Save(fs) + } + + return nil +} + +// validateBranchNotActiveInAnySessions returns an error if the specified branch is currently +// selected as the active branch for any active server sessions. +func validateBranchNotActiveInAnySession(ctx *sql.Context, branchName string) error { + currentDbName, _, err := getRevisionForRevisionDatabase(ctx, ctx.GetCurrentDatabase()) + if err != nil { + return err + } + + if currentDbName == "" { + return nil + } + + if sqlserver.RunningInServerMode() == false { + return nil + } + + runningServer := sqlserver.GetRunningServer() + if runningServer == nil { + return nil + } + sessionManager := runningServer.SessionManager() + branchRef := ref.NewBranchRef(branchName) + + return sessionManager.Iter(func(session sql.Session) (bool, error) { + dsess, ok := session.(*dsess.DoltSession) + if !ok { + return false, fmt.Errorf("unexpected session type: %T", session) + } + + sessionDatabase := dsess.Session.GetCurrentDatabase() + sessionDbName, _, err := getRevisionForRevisionDatabase(ctx, dsess.GetCurrentDatabase()) + if err != nil { + return false, err + } + + if len(sessionDatabase) == 0 || sessionDbName != currentDbName { + return false, nil + } + + activeBranchRef, err := dsess.CWBHeadRef(ctx, sessionDatabase) + if err != nil { + return false, err + } + + if ref.Equals(branchRef, activeBranchRef) { + return false, fmt.Errorf("unsafe to delete or rename branches in use in other sessions; " + + "use --force to force the change") + } + + return false, nil + }) +} + +//TODO: the config should be available via the context, it's unnecessary to do an env.Load here and this should be removed +func loadConfig(ctx *sql.Context) *env.DoltCliConfig { + // When executing branch actions from SQL, we don't have access to a DoltEnv like we do from + // within the CLI. We can fake it here enough to get a DoltCliConfig, but we can't rely on the + // DoltEnv because tests and production will run with different settings (e.g. in-mem versus file). + dEnv := env.Load(ctx, env.GetCurrentUserHomeDir, filesys.LocalFS, doltdb.LocalDirDoltDB, "") + return dEnv.Config +} + +func createNewBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults) error { + var branchName string + var startPt = "HEAD" + if apr.NArg() == 1 { + branchName = apr.Arg(0) + } else if apr.NArg() == 2 { + branchName = apr.Arg(0) + startPt = apr.Arg(1) + if len(startPt) == 0 { + return InvalidArgErr + } + } + + if len(branchName) == 0 { + return EmptyBranchNameErr + } + + if err := branch_control.CanCreateBranch(ctx, branchName); err != nil { + return err + } + return actions.CreateBranchWithStartPt(ctx, dbData, branchName, startPt, apr.Contains(cli.ForceFlag)) +} + +func copyBranch(ctx *sql.Context, dbData env.DbData, apr *argparser.ArgParseResults) error { + if apr.NArg() != 2 { + return InvalidArgErr + } + + srcBr := apr.Args[0] + if len(srcBr) == 0 { + return EmptyBranchNameErr + } + + destBr := apr.Args[1] + if len(destBr) == 0 { + return EmptyBranchNameErr + } + + force := apr.Contains(cli.ForceFlag) + return copyABranch(ctx, dbData, srcBr, destBr, force) +} + +func copyABranch(ctx *sql.Context, dbData env.DbData, srcBr string, destBr string, force bool) error { + if err := branch_control.CanCreateBranch(ctx, destBr); err != nil { + return err + } + // If force is enabled, we can overwrite the destination branch, so we require a permission check here, even if the + // destination branch doesn't exist. An unauthorized user could simply rerun the command without the force flag. + if force { + if err := branch_control.CanDeleteBranch(ctx, destBr); err != nil { + return err + } + } + err := actions.CopyBranchOnDB(ctx, dbData.Ddb, srcBr, destBr, force) + if err != nil { + if err == doltdb.ErrBranchNotFound { + return errors.New(fmt.Sprintf("fatal: A branch named '%s' not found", srcBr)) + } else if err == actions.ErrAlreadyExists { + return errors.New(fmt.Sprintf("fatal: A branch named '%s' already exists.", destBr)) + } else if err == doltdb.ErrInvBranchName { + return errors.New(fmt.Sprintf("fatal: '%s' is not a valid branch name.", destBr)) + } else { + return errors.New(fmt.Sprintf("fatal: Unexpected error copying branch from '%s' to '%s'", srcBr, destBr)) + } + } + err = branch_control.AddAdminForContext(ctx, destBr) + if err != nil { + return err + } + + return nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_checkout.go b/go/libraries/doltcore/sqle/dprocedures/dolt_checkout.go index 4a0d23a0d3..bf03a311a9 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_checkout.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_checkout.go @@ -15,16 +15,258 @@ package dprocedures import ( + "errors" + "fmt" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/cmd/dolt/errhand" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/ref" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/store/hash" ) +var ErrEmptyBranchName = errors.New("error: cannot checkout empty string") + // doltCheckout is the stored procedure version of the function `dolt_checkout`. func doltCheckout(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltCheckout(ctx, args) + res, err := doDoltCheckout(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltCheckout(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return 1, fmt.Errorf("Empty database name.") + } + + dbName, _, err := getRevisionForRevisionDatabase(ctx, dbName) + if err != nil { + return -1, err + } + + apr, err := cli.CreateCheckoutArgParser().Parse(args) + if err != nil { + return 1, err + } + + if (apr.Contains(cli.CheckoutCoBranch) && apr.NArg() > 1) || (!apr.Contains(cli.CheckoutCoBranch) && apr.NArg() == 0) { + return 1, errors.New("Improper usage.") + } + + // Checking out new branch. + dSess := dsess.DSessFromSess(ctx.Session) + dbData, ok := dSess.GetDbData(ctx, dbName) + if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + if newBranch, newBranchOk := apr.GetValue(cli.CheckoutCoBranch); newBranchOk { + if len(newBranch) == 0 { + err = errors.New("error: cannot checkout empty string") + } else if len(apr.Args) > 0 { + err = checkoutNewBranch(ctx, dbName, dbData, newBranch, apr.Arg(0)) + } else { + err = checkoutNewBranch(ctx, dbName, dbData, newBranch, "") + } + + if err != nil { + return 1, err + } + + return 0, nil + } + + name := apr.Arg(0) + if len(name) == 0 { + return 1, ErrEmptyBranchName + } + + // Check if user wants to checkout branch. + if isBranch, err := actions.IsBranch(ctx, dbData.Ddb, name); err != nil { + return 1, err + } else if isBranch { + err = checkoutBranch(ctx, dbName, name) + if errors.Is(err, doltdb.ErrWorkingSetNotFound) { + // If there is a branch but there is no working set, + // somehow the local branch ref was created without a + // working set. This happened with old versions of dolt + // when running as a read replica, for example. Try to + // create a working set pointing at the existing branch + // HEAD and check out the branch again. + // + // TODO: This is all quite racey, but so is the + // handling in DoltDB, etc. + err = createWorkingSetForLocalBranch(ctx, dbData.Ddb, name) + if err != nil { + return 1, err + } + + err = checkoutBranch(ctx, dbName, name) + } + if err != nil { + return 1, err + } + return 0, nil + } + + roots, ok := dSess.GetRoots(ctx, dbName) + if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + err = checkoutTables(ctx, roots, dbName, args) + if err != nil && apr.NArg() == 1 { + err = checkoutRemoteBranch(ctx, dbName, dbData, name) + } + + if err != nil { + return 1, err + } + + return 0, nil +} + +// createWorkingSetForLocalBranch will make a new working set for a local +// branch ref if one does not already exist. Can be used to fix up local branch +// state when branches have been created without working sets in the past. +// +// This makes it so that dolt_checkout can checkout workingset-less branches, +// the same as `dolt checkout` at the CLI. The semantics of exactly what +// working set gets created in the new case are different, since the CLI takes +// the working set with it. +// +// TODO: This is cribbed heavily from doltdb.*DoltDB.NewBranchAtCommit. +func createWorkingSetForLocalBranch(ctx *sql.Context, ddb *doltdb.DoltDB, branchName string) error { + branchRef := ref.NewBranchRef(branchName) + commit, err := ddb.ResolveCommitRef(ctx, branchRef) + if err != nil { + return err + } + + commitRoot, err := commit.GetRootValue(ctx) + if err != nil { + return err + } + + wsRef, err := ref.WorkingSetRefForHead(branchRef) + if err != nil { + return err + } + + _, err = ddb.ResolveWorkingSet(ctx, wsRef) + if err == nil { + // This already exists. Return... + return nil + } + if !errors.Is(err, doltdb.ErrWorkingSetNotFound) { + return err + } + + ws := doltdb.EmptyWorkingSet(wsRef).WithWorkingRoot(commitRoot).WithStagedRoot(commitRoot) + return ddb.UpdateWorkingSet(ctx, wsRef, ws, hash.Hash{} /* current hash... */, doltdb.TodoWorkingSetMeta()) +} + +// getRevisionForRevisionDatabase returns the root database name and revision for a database, or just the root database name if the specified db name is not a revision database. +func getRevisionForRevisionDatabase(ctx *sql.Context, dbName string) (string, string, error) { + doltsess, ok := ctx.Session.(*dsess.DoltSession) + if !ok { + return "", "", fmt.Errorf("unexpected session type: %T", ctx.Session) + } + + provider := doltsess.Provider() + return provider.GetRevisionForRevisionDatabase(ctx, dbName) +} + +// checkoutRemoteBranch checks out a remote branch creating a new local branch with the same name as the remote branch +// and set its upstream. The upstream persists out of sql session. +func checkoutRemoteBranch(ctx *sql.Context, dbName string, dbData env.DbData, branchName string) error { + remoteRefs, err := actions.GetRemoteBranchRef(ctx, dbData.Ddb, branchName) + if err != nil { + return errors.New("fatal: unable to read from data repository") + } + + if len(remoteRefs) == 0 { + return fmt.Errorf("error: could not find %s", branchName) + } else if len(remoteRefs) == 1 { + remoteRef := remoteRefs[0] + err := checkoutNewBranch(ctx, dbName, dbData, branchName, remoteRef.String()) + if err != nil { + return err + } + + refSpec, err := ref.ParseRefSpecForRemote(remoteRef.GetRemote(), remoteRef.GetBranch()) + if err != nil { + return errhand.BuildDError(fmt.Errorf("%w: '%s'", err, remoteRef.GetRemote()).Error()).Build() + } + + src := refSpec.SrcRef(dbData.Rsr.CWBHeadRef()) + dest := refSpec.DestRef(src) + + return dbData.Rsw.UpdateBranch(src.GetPath(), env.BranchConfig{ + Merge: ref.MarshalableRef{ + Ref: dest, + }, + Remote: remoteRef.GetRemote(), + }) + } else { + return fmt.Errorf("'%s' matched multiple (%v) remote tracking branches", branchName, len(remoteRefs)) + } +} + +func checkoutNewBranch(ctx *sql.Context, dbName string, dbData env.DbData, branchName, startPt string) error { + if len(branchName) == 0 { + return ErrEmptyBranchName + } + + if startPt == "" { + startPt = "head" + } + + err := actions.CreateBranchWithStartPt(ctx, dbData, branchName, startPt, false) + if err != nil { + return err + } + + return checkoutBranch(ctx, dbName, branchName) +} + +func checkoutBranch(ctx *sql.Context, dbName string, branchName string) error { + wsRef, err := ref.WorkingSetRefForHead(ref.NewBranchRef(branchName)) + if err != nil { + return err + } + + if ctx.GetCurrentDatabase() != dbName { + ctx.SetCurrentDatabase(dbName) + } + + dSess := dsess.DSessFromSess(ctx.Session) + return dSess.SwitchWorkingSet(ctx, dbName, wsRef) +} + +func checkoutTables(ctx *sql.Context, roots doltdb.Roots, name string, tables []string) error { + roots, err := actions.MoveTablesFromHeadToWorking(ctx, roots, tables) + + if err != nil { + if doltdb.IsRootValUnreachable(err) { + rt := doltdb.GetUnreachableRootType(err) + return fmt.Errorf("error: unable to read the %s", rt.String()) + } else if actions.IsTblNotExist(err) { + return fmt.Errorf("error: given tables do not exist") + } else { + return fmt.Errorf("fatal: Unexpected error checking out tables") + } + } + + dSess := dsess.DSessFromSess(ctx.Session) + return dSess.SetRoots(ctx, name, roots) +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_clean.go b/go/libraries/doltcore/sqle/dprocedures/dolt_clean.go index eb68735917..318ea864c9 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_clean.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_clean.go @@ -15,16 +15,56 @@ package dprocedures import ( + "fmt" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" ) // doltClean is the stored procedure version of the function `dolt_clean`. func doltClean(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltClean(ctx, args) + res, err := doDoltClean(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltClean(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return 1, fmt.Errorf("Empty database name.") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return statusErr, err + } + + dSess := dsess.DSessFromSess(ctx.Session) + + apr, err := cli.CreateCleanArgParser().Parse(args) + if err != nil { + return 1, err + } + + // Get all the needed roots. + roots, ok := dSess.GetRoots(ctx, dbName) + if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + roots, err = actions.CleanUntracked(ctx, roots, apr.Args, apr.ContainsAll(cli.DryRunFlag)) + if err != nil { + return 1, fmt.Errorf("failed to clean; %w", err) + } + + err = dSess.SetRoots(ctx, dbName, roots) + if err != nil { + return 1, err + } + return 0, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go b/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go index 27cb440898..6e49d2d5ce 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go @@ -15,16 +15,158 @@ package dprocedures import ( - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "errors" + "fmt" "github.com/dolthub/go-mysql-server/sql" + "github.com/dolthub/vitess/go/vt/proto/query" + + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" ) -// doltCommit is the stored procedure version of the functions `commit` and `dolt_commit`. +var hashType = sql.MustCreateString(query.Type_TEXT, 32, sql.Collation_ascii_bin) + +// doltCommit is the stored procedure version for the CLI function `commit`. func doltCommit(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltCommit(ctx, args) + res, err := doDoltCommit(ctx, args) if err != nil { return nil, err } return rowToIter(res), nil } + +// doltCommitHashOut is the stored procedure version for the CLI function `commit`. The first parameter is the variable +// to set the hash of. +func doltCommitHashOut(ctx *sql.Context, outHash *string, args ...string) (sql.RowIter, error) { + res, err := doDoltCommit(ctx, args) + if err != nil { + return nil, err + } + *outHash = res + return rowToIter(res), nil +} + +func doDoltCommit(ctx *sql.Context, args []string) (string, error) { + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return "", err + } + // Get the information for the sql context. + dbName := ctx.GetCurrentDatabase() + + apr, err := cli.CreateCommitArgParser().Parse(args) + if err != nil { + return "", err + } + + dSess := dsess.DSessFromSess(ctx.Session) + roots, ok := dSess.GetRoots(ctx, dbName) + if !ok { + return "", fmt.Errorf("Could not load database %s", dbName) + } + + if apr.Contains(cli.UpperCaseAllFlag) { + roots, err = actions.StageAllTables(ctx, roots) + if err != nil { + return "", fmt.Errorf(err.Error()) + } + } else if apr.Contains(cli.AllFlag) { + roots, err = actions.StageModifiedAndDeletedTables(ctx, roots) + if err != nil { + return "", fmt.Errorf(err.Error()) + } + } + + var name, email string + if authorStr, ok := apr.GetValue(cli.AuthorParam); ok { + name, email, err = cli.ParseAuthor(authorStr) + if err != nil { + return "", err + } + } else { + name = dSess.Username() + email = dSess.Email() + } + + amend := apr.Contains(cli.AmendFlag) + + msg, msgOk := apr.GetValue(cli.MessageArg) + if !msgOk { + if amend { + commit, err := dSess.GetHeadCommit(ctx, dbName) + if err != nil { + return "", err + } + commitMeta, err := commit.GetCommitMeta(ctx) + if err != nil { + return "", err + } + msg = commitMeta.Description + } else { + return "", fmt.Errorf("Must provide commit message.") + } + } + + t := ctx.QueryTime() + if commitTimeStr, ok := apr.GetValue(cli.DateParam); ok { + var err error + t, err = cli.ParseDate(commitTimeStr) + + if err != nil { + return "", fmt.Errorf(err.Error()) + } + } + + pendingCommit, err := dSess.NewPendingCommit(ctx, dbName, roots, actions.CommitStagedProps{ + Message: msg, + Date: t, + AllowEmpty: apr.Contains(cli.AllowEmptyFlag), + Amend: amend, + Force: apr.Contains(cli.ForceFlag), + Name: name, + Email: email, + }) + if err != nil { + return "", err + } + + // Nothing to commit, and we didn't pass --allowEmpty + if pendingCommit == nil { + return "", errors.New("nothing to commit") + } + + newCommit, err := dSess.DoltCommit(ctx, dbName, dSess.GetTransaction(), pendingCommit) + if err != nil { + return "", err + } + + h, err := newCommit.HashOf() + if err != nil { + return "", err + } + + return h.String(), nil +} + +func getDoltArgs(ctx *sql.Context, row sql.Row, children []sql.Expression) ([]string, error) { + args := make([]string, len(children)) + for i := range children { + childVal, err := children[i].Eval(ctx, row) + + if err != nil { + return nil, err + } + + text, err := sql.Text.Convert(childVal) + + if err != nil { + return nil, err + } + + args[i] = text.(string) + } + + return args, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_fetch.go b/go/libraries/doltcore/sqle/dprocedures/dolt_fetch.go index 9d4826895b..332c4f8396 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_fetch.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_fetch.go @@ -15,16 +15,63 @@ package dprocedures import ( + "fmt" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/ref" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" ) // doltFetch is the stored procedure version of the function `dolt_fetch`. func doltFetch(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltFetch(ctx, args) + res, err := doDoltFetch(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltFetch(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return cmdFailure, fmt.Errorf("empty database name") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return cmdFailure, err + } + + sess := dsess.DSessFromSess(ctx.Session) + dbData, ok := sess.GetDbData(ctx, dbName) + if !ok { + return cmdFailure, fmt.Errorf("Could not load database %s", dbName) + } + + apr, err := cli.CreateFetchArgParser().Parse(args) + if err != nil { + return cmdFailure, err + } + + remote, refSpecs, err := env.NewFetchOpts(apr.Args, dbData.Rsr) + if err != nil { + return cmdFailure, err + } + + updateMode := ref.UpdateMode{Force: apr.Contains(cli.ForceFlag)} + + srcDB, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, remote, false) + if err != nil { + return 1, err + } + + err = actions.FetchRefSpecs(ctx, dbData, srcDB, refSpecs, remote, updateMode, runProgFuncs, stopProgFuncs) + if err != nil { + return cmdFailure, fmt.Errorf("fetch failed: %w", err) + } + return cmdSuccess, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_merge.go b/go/libraries/doltcore/sqle/dprocedures/dolt_merge.go index a2538845f7..194247b21f 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_merge.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_merge.go @@ -15,16 +15,444 @@ package dprocedures import ( - "github.com/dolthub/go-mysql-server/sql" + "errors" + "fmt" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/go-mysql-server/sql" + goerrors "gopkg.in/src-d/go-errors.v1" + + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/merge" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/libraries/doltcore/table/editor" + "github.com/dolthub/dolt/go/libraries/utils/argparser" ) +const DoltMergeWarningCode int = 1105 // Since this our own custom warning we'll use 1105, the code for an unknown error + +const ( + noConflictsOrViolations int = 0 + hasConflictsOrViolations int = 1 +) + +const ( + threeWayMerge = 0 + fastForwardMerge = 1 +) + +var ErrUncommittedChanges = goerrors.NewKind("cannot merge with uncommitted changes") + // doltMerge is the stored procedure version of the functions `merge` and `dolt_merge`. func doltMerge(ctx *sql.Context, args ...string) (sql.RowIter, error) { - hasConflicts, ff, err := dfunctions.DoDoltMerge(ctx, args) + hasConflicts, ff, err := doDoltMerge(ctx, args) if err != nil { return nil, err } return rowToIter(int64(ff), int64(hasConflicts)), nil } + +// doDoltMerge returns has_conflicts and fast_forward status +func doDoltMerge(ctx *sql.Context, args []string) (int, int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("Empty database name.") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + sess := dsess.DSessFromSess(ctx.Session) + + apr, err := cli.CreateMergeArgParser().Parse(args) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + if apr.ContainsAll(cli.SquashParam, cli.NoFFParam) { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("error: Flags '--%s' and '--%s' cannot be used together.\n", cli.SquashParam, cli.NoFFParam) + } + + ws, err := sess.WorkingSet(ctx, dbName) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + roots, ok := sess.GetRoots(ctx, dbName) + if !ok { + return noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) + } + + if apr.Contains(cli.AbortParam) { + if !ws.MergeActive() { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("fatal: There is no merge to abort") + } + + ws, err = abortMerge(ctx, ws, roots) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + err := sess.SetWorkingSet(ctx, dbName, ws) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + err = sess.CommitWorkingSet(ctx, dbName, sess.GetTransaction()) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + return noConflictsOrViolations, threeWayMerge, nil + } + + branchName := apr.Arg(0) + + mergeSpec, err := createMergeSpec(ctx, sess, dbName, apr, branchName) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + dbData, ok := sess.GetDbData(ctx, dbName) + if !ok { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("Could not load database %s", dbName) + } + msg := fmt.Sprintf("Merge branch '%s' into %s", branchName, dbData.Rsr.CWBHeadRef().GetPath()) + if userMsg, mOk := apr.GetValue(cli.MessageArg); mOk { + msg = userMsg + } + + ws, conflicts, fastForward, err := performMerge(ctx, sess, roots, ws, dbName, mergeSpec, apr.Contains(cli.NoCommitFlag), msg) + if err != nil || conflicts != 0 || fastForward != 0 { + return conflicts, fastForward, err + } + + return conflicts, fastForward, nil +} + +// performMerge encapsulates server merge logic, switching between +// fast-forward, no fast-forward, merge commit, and merging into working set. +// Returns a new WorkingSet, whether there were merge conflicts, and whether a +// fast-forward was performed. This commits the working set if merge is successful and +// 'no-commit' flag is not defined. +// TODO FF merging commit with constraint violations requires `constraint verify` +func performMerge(ctx *sql.Context, sess *dsess.DoltSession, roots doltdb.Roots, ws *doltdb.WorkingSet, dbName string, spec *merge.MergeSpec, noCommit bool, msg string) (*doltdb.WorkingSet, int, int, error) { + // todo: allow merges even when an existing merge is uncommitted + if ws.MergeActive() { + return ws, noConflictsOrViolations, threeWayMerge, doltdb.ErrMergeActive + } + + err := checkForUncommittedChanges(ctx, roots.Working, roots.Head) + if err != nil { + return ws, noConflictsOrViolations, threeWayMerge, err + } + + dbData, ok := sess.GetDbData(ctx, dbName) + if !ok { + return ws, noConflictsOrViolations, threeWayMerge, fmt.Errorf("failed to get dbData") + } + + canFF, err := spec.HeadC.CanFastForwardTo(ctx, spec.MergeC) + if err != nil { + switch err { + case doltdb.ErrIsAhead, doltdb.ErrUpToDate: + ctx.Warn(DoltMergeWarningCode, err.Error()) + default: + return ws, noConflictsOrViolations, threeWayMerge, err + } + } + + if canFF { + if spec.Noff { + ws, err = executeNoFFMerge(ctx, sess, spec, dbName, ws, dbData) + if err == doltdb.ErrUnresolvedConflictsOrViolations { + // if there are unresolved conflicts, write the resulting working set back to the session and return an + // error message + wsErr := sess.SetWorkingSet(ctx, dbName, ws) + if wsErr != nil { + return ws, hasConflictsOrViolations, threeWayMerge, wsErr + } + + ctx.Warn(DoltMergeWarningCode, err.Error()) + + return ws, hasConflictsOrViolations, threeWayMerge, nil + } + return ws, noConflictsOrViolations, fastForwardMerge, err + } + + ws, err = executeFFMerge(ctx, dbName, spec.Squash, ws, dbData, spec.MergeC) + return ws, noConflictsOrViolations, fastForwardMerge, err + } + + dbState, ok, err := sess.LookupDbState(ctx, dbName) + if err != nil { + return ws, noConflictsOrViolations, threeWayMerge, err + } else if !ok { + return ws, noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) + } + + ws, err = executeMerge(ctx, spec.Squash, spec.HeadC, spec.MergeC, spec.MergeCSpecStr, ws, dbState.EditOpts()) + if err == doltdb.ErrUnresolvedConflictsOrViolations { + // if there are unresolved conflicts, write the resulting working set back to the session and return an + // error message + wsErr := sess.SetWorkingSet(ctx, dbName, ws) + if wsErr != nil { + return ws, hasConflictsOrViolations, threeWayMerge, wsErr + } + + ctx.Warn(DoltMergeWarningCode, err.Error()) + + return ws, hasConflictsOrViolations, threeWayMerge, nil + } else if err != nil { + return ws, noConflictsOrViolations, threeWayMerge, err + } + + err = sess.SetWorkingSet(ctx, dbName, ws) + if err != nil { + return ws, noConflictsOrViolations, threeWayMerge, err + } + + if !noCommit { + author := fmt.Sprintf("%s <%s>", spec.Name, spec.Email) + _, err = doDoltCommit(ctx, []string{"-m", msg, "--author", author}) + if err != nil { + return ws, noConflictsOrViolations, threeWayMerge, fmt.Errorf("dolt_commit failed") + } + } + + return ws, noConflictsOrViolations, threeWayMerge, nil +} + +func abortMerge(ctx *sql.Context, workingSet *doltdb.WorkingSet, roots doltdb.Roots) (*doltdb.WorkingSet, error) { + tbls, err := doltdb.UnionTableNames(ctx, roots.Working, roots.Staged, roots.Head) + if err != nil { + return nil, err + } + + roots, err = actions.MoveTablesFromHeadToWorking(ctx, roots, tbls) + if err != nil { + return nil, err + } + + // TODO: this doesn't seem right, it sets the root that we already edited above + workingSet = workingSet.AbortMerge() + return workingSet, nil +} + +func executeMerge(ctx *sql.Context, squash bool, head, cm *doltdb.Commit, cmSpec string, ws *doltdb.WorkingSet, opts editor.Options) (*doltdb.WorkingSet, error) { + mergeRoot, mergeStats, err := merge.MergeCommits(ctx, head, cm, opts) + + if err != nil { + switch err { + case doltdb.ErrUpToDate: + return nil, errors.New("Already up to date.") + case merge.ErrFastForward: + panic("fast forward merge") + default: + return nil, err + } + } + + return mergeRootToWorking(squash, ws, mergeRoot, cm, cmSpec, mergeStats) +} + +func executeFFMerge(ctx *sql.Context, dbName string, squash bool, ws *doltdb.WorkingSet, dbData env.DbData, cm2 *doltdb.Commit) (*doltdb.WorkingSet, error) { + rv, err := cm2.GetRootValue(ctx) + if err != nil { + return ws, err + } + + // TODO: This is all incredibly suspect, needs to be replaced with library code that is functional instead of + // altering global state + if !squash { + err = dbData.Ddb.FastForward(ctx, dbData.Rsr.CWBHeadRef(), cm2) + if err != nil { + return ws, err + } + } + + ws = ws.WithWorkingRoot(rv).WithStagedRoot(rv) + + // We need to assign the working set to the session but ensure that its state is not labeled as dirty (ffs are clean + // merges). Hence, we go ahead and commit the working set to the transaction. + sess := dsess.DSessFromSess(ctx.Session) + + err = sess.SetWorkingSet(ctx, dbName, ws) + if err != nil { + return ws, err + } + + // We only fully commit our transaction when we are not squashing. + if !squash { + err = sess.CommitWorkingSet(ctx, dbName, sess.GetTransaction()) + if err != nil { + return ws, err + } + } + + return ws, nil +} + +func executeNoFFMerge( + ctx *sql.Context, + dSess *dsess.DoltSession, + spec *merge.MergeSpec, + dbName string, + ws *doltdb.WorkingSet, + dbData env.DbData, +) (*doltdb.WorkingSet, error) { + mergeRoot, err := spec.MergeC.GetRootValue(ctx) + if err != nil { + return nil, err + } + + ws, err = mergeRootToWorking(false, ws, mergeRoot, spec.MergeC, spec.MergeCSpecStr, map[string]*merge.MergeStats{}) + if err != nil { + // This error is recoverable, so we return a working set value along with the error + return ws, err + } + + // Save our work so far in the session, as it will be referenced by the commit call below (badly in need of a + // refactoring) + err = dSess.SetWorkingSet(ctx, dbName, ws) + if err != nil { + return nil, err + } + + // The roots need refreshing after the above + roots, _ := dSess.GetRoots(ctx, dbName) + + pendingCommit, err := dSess.NewPendingCommit(ctx, dbName, roots, actions.CommitStagedProps{ + Message: spec.Msg, + Date: spec.Date, + AllowEmpty: spec.AllowEmpty, + Force: spec.Force, + Name: spec.Name, + Email: spec.Email, + }) + if err != nil { + return nil, err + } + + if pendingCommit == nil { + return nil, errors.New("nothing to commit") + } + + _, err = dSess.DoltCommit(ctx, dbName, dSess.GetTransaction(), pendingCommit) + if err != nil { + return nil, err + } + + return ws, nil +} + +func createMergeSpec(ctx *sql.Context, sess *dsess.DoltSession, dbName string, apr *argparser.ArgParseResults, commitSpecStr string) (*merge.MergeSpec, error) { + ddb, ok := sess.GetDoltDB(ctx, dbName) + + dbData, ok := sess.GetDbData(ctx, dbName) + + msg, ok := apr.GetValue(cli.MessageArg) + if !ok { + // TODO probably change, but we can't open editor so it'll have to be automated + msg = "automatic SQL merge" + } + + var err error + var name, email string + if authorStr, ok := apr.GetValue(cli.AuthorParam); ok { + name, email, err = cli.ParseAuthor(authorStr) + if err != nil { + return nil, err + } + } else { + name = sess.Username() + email = sess.Email() + } + + t := ctx.QueryTime() + if commitTimeStr, ok := apr.GetValue(cli.DateParam); ok { + t, err = cli.ParseDate(commitTimeStr) + if err != nil { + return nil, err + } + } + + roots, ok := sess.GetRoots(ctx, dbName) + if !ok { + return nil, sql.ErrDatabaseNotFound.New(dbName) + } + + if apr.Contains(cli.NoCommitFlag) && apr.Contains(cli.CommitFlag) { + return nil, errors.New("cannot define both 'commit' and 'no-commit' flags at the same time") + } + mergeSpec, err := merge.NewMergeSpec(ctx, dbData.Rsr, ddb, roots, name, email, msg, commitSpecStr, apr.Contains(cli.SquashParam), apr.Contains(cli.NoFFParam), apr.Contains(cli.ForceFlag), apr.Contains(cli.NoCommitFlag), apr.Contains(cli.NoEditFlag), t) + if err != nil { + return nil, err + } + return mergeSpec, nil +} + +// TODO: this copied from commands/merge.go because the latter isn't reusable. Fix that. +func mergeRootToWorking( + squash bool, + ws *doltdb.WorkingSet, + mergedRoot *doltdb.RootValue, + cm2 *doltdb.Commit, + cm2Spec string, + mergeStats map[string]*merge.MergeStats, +) (*doltdb.WorkingSet, error) { + + workingRoot := mergedRoot + if !squash { + ws = ws.StartMerge(cm2, cm2Spec) + } + + ws = ws.WithWorkingRoot(workingRoot).WithStagedRoot(workingRoot) + if checkForConflicts(mergeStats) || checkForViolations(mergeStats) { + // this error is recoverable in-session, so we return the new ws along with the error + return ws, doltdb.ErrUnresolvedConflictsOrViolations + } + + return ws, nil +} + +func checkForUncommittedChanges(ctx *sql.Context, root *doltdb.RootValue, headRoot *doltdb.RootValue) error { + rh, err := root.HashOf() + + if err != nil { + return err + } + + hrh, err := headRoot.HashOf() + + if err != nil { + return err + } + + if rh != hrh { + return ErrUncommittedChanges.New() + } + return nil +} + +func checkForConflicts(tblToStats map[string]*merge.MergeStats) bool { + for _, stats := range tblToStats { + if stats.Operation == merge.TableModified && stats.Conflicts > 0 { + return true + } + } + + return false +} + +func checkForViolations(tblToStats map[string]*merge.MergeStats) bool { + for _, stats := range tblToStats { + if stats.ConstraintViolations > 0 { + return true + } + } + return false +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_pull.go b/go/libraries/doltcore/sqle/dprocedures/dolt_pull.go index 1c2add522b..ba9c01202f 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_pull.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_pull.go @@ -15,16 +15,222 @@ package dprocedures import ( + "context" + "errors" + "fmt" + "sync" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/ref" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/store/datas/pull" ) // doltPull is the stored procedure version of the function `dolt_pull`. func doltPull(ctx *sql.Context, args ...string) (sql.RowIter, error) { - conflicts, ff, err := dfunctions.DoDoltPull(ctx, args) + conflicts, ff, err := doDoltPull(ctx, args) if err != nil { return nil, err } return rowToIter(int64(ff), int64(conflicts)), nil } + +// doDoltPull returns conflicts, fast_forward statuses +func doDoltPull(ctx *sql.Context, args []string) (int, int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("empty database name.") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + sess := dsess.DSessFromSess(ctx.Session) + dbData, ok := sess.GetDbData(ctx, dbName) + if !ok { + return noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) + } + + apr, err := cli.CreatePullArgParser().Parse(args) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + if apr.NArg() > 2 { + return noConflictsOrViolations, threeWayMerge, actions.ErrInvalidPullArgs + } + + var remoteName, remoteRefName string + if apr.NArg() == 1 { + remoteName = apr.Arg(0) + } else if apr.NArg() == 2 { + remoteName = apr.Arg(0) + remoteRefName = apr.Arg(1) + } + + pullSpec, err := env.NewPullSpec(ctx, dbData.Rsr, remoteName, remoteRefName, apr.Contains(cli.SquashParam), apr.Contains(cli.NoFFParam), apr.Contains(cli.NoCommitFlag), apr.Contains(cli.NoEditFlag), apr.Contains(cli.ForceFlag), apr.NArg() == 1) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + srcDB, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, pullSpec.Remote, false) + if err != nil { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("failed to get remote db; %w", err) + } + + ws, err := sess.WorkingSet(ctx, dbName) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + // Fetch all references + branchRefs, err := srcDB.GetHeadRefs(ctx) + if err != nil { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("%w: %s", env.ErrFailedToReadDb, err.Error()) + } + + _, hasBranch, err := srcDB.HasBranch(ctx, pullSpec.Branch.GetPath()) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + if !hasBranch { + return noConflictsOrViolations, threeWayMerge, + fmt.Errorf("branch %q not found on remote", pullSpec.Branch.GetPath()) + } + + var conflicts int + var fastForward int + for _, refSpec := range pullSpec.RefSpecs { + rsSeen := false // track invalid refSpecs + for _, branchRef := range branchRefs { + remoteTrackRef := refSpec.DestRef(branchRef) + + if remoteTrackRef == nil { + continue + } + + rsSeen = true + tmpDir, err := dbData.Rsw.TempTableFilesDir() + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + // todo: can we pass nil for either of the channels? + srcDBCommit, err := actions.FetchRemoteBranch(ctx, tmpDir, pullSpec.Remote, srcDB, dbData.Ddb, branchRef, runProgFuncs, stopProgFuncs) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + // TODO: this could be replaced with a canFF check to test for error + err = dbData.Ddb.FastForward(ctx, remoteTrackRef, srcDBCommit) + if err != nil { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("fetch failed; %w", err) + } + + // Only merge iff branch is current branch and there is an upstream set (pullSpec.Branch is set to nil if there is no upstream) + if branchRef != pullSpec.Branch { + continue + } + + roots, ok := sess.GetRoots(ctx, dbName) + if !ok { + return noConflictsOrViolations, threeWayMerge, sql.ErrDatabaseNotFound.New(dbName) + } + + mergeSpec, err := createMergeSpec(ctx, sess, dbName, apr, remoteTrackRef.String()) + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + + msg := fmt.Sprintf("Merge branch '%s' of %s into %s", pullSpec.Branch.GetPath(), pullSpec.Remote.Url, dbData.Rsr.CWBHeadRef().GetPath()) + ws, conflicts, fastForward, err = performMerge(ctx, sess, roots, ws, dbName, mergeSpec, apr.Contains(cli.NoCommitFlag), msg) + if err != nil && !errors.Is(doltdb.ErrUpToDate, err) { + return conflicts, fastForward, err + } + + err = sess.SetWorkingSet(ctx, dbName, ws) + if err != nil { + return conflicts, fastForward, err + } + } + if !rsSeen { + return noConflictsOrViolations, threeWayMerge, fmt.Errorf("%w: '%s'", ref.ErrInvalidRefSpec, refSpec.GetRemRefToLocal()) + } + } + + tmpDir, err := dbData.Rsw.TempTableFilesDir() + if err != nil { + return noConflictsOrViolations, threeWayMerge, err + } + err = actions.FetchFollowTags(ctx, tmpDir, srcDB, dbData.Ddb, runProgFuncs, stopProgFuncs) + if err != nil { + return conflicts, fastForward, err + } + + return conflicts, fastForward, nil +} + +//TODO: remove this as it does not do anything useful +func pullerProgFunc(ctx context.Context, statsCh <-chan pull.Stats) { + for { + if ctx.Err() != nil { + return + } + select { + case <-ctx.Done(): + return + case <-statsCh: + default: + } + } +} + +//TODO: remove this as it does not do anything useful +func progFunc(ctx context.Context, progChan <-chan pull.PullProgress) { + for { + if ctx.Err() != nil { + return + } + select { + case <-ctx.Done(): + return + case <-progChan: + default: + } + } +} + +//TODO: remove this as it does not do anything useful +func runProgFuncs(ctx context.Context) (*sync.WaitGroup, chan pull.PullProgress, chan pull.Stats) { + statsCh := make(chan pull.Stats) + progChan := make(chan pull.PullProgress) + wg := &sync.WaitGroup{} + + wg.Add(1) + go func() { + defer wg.Done() + progFunc(ctx, progChan) + }() + + wg.Add(1) + go func() { + defer wg.Done() + pullerProgFunc(ctx, statsCh) + }() + + return wg, progChan, statsCh +} + +//TODO: remove this as it does not do anything useful +func stopProgFuncs(cancel context.CancelFunc, wg *sync.WaitGroup, progChan chan pull.PullProgress, statsCh chan pull.Stats) { + cancel() + close(progChan) + close(statsCh) + wg.Wait() +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_push.go b/go/libraries/doltcore/sqle/dprocedures/dolt_push.go index c74523a5f2..1d1e5cec2b 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_push.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_push.go @@ -15,16 +15,81 @@ package dprocedures import ( + "fmt" + "strconv" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/store/datas" ) // doltPush is the stored procedure version of the function `dolt_push`. func doltPush(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltPush(ctx, args) + res, err := doDoltPush(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltPush(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return cmdFailure, fmt.Errorf("empty database name") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return cmdFailure, err + } + + sess := dsess.DSessFromSess(ctx.Session) + dbData, ok := sess.GetDbData(ctx, dbName) + + if !ok { + return cmdFailure, fmt.Errorf("could not load database %s", dbName) + } + + apr, err := cli.CreatePushArgParser().Parse(args) + if err != nil { + return cmdFailure, err + } + + autoSetUpRemote := loadConfig(ctx).GetStringOrDefault(env.PushAutoSetupRemote, "false") + pushAutoSetUpRemote, err := strconv.ParseBool(autoSetUpRemote) + if err != nil { + return cmdFailure, err + } + + opts, err := env.NewPushOpts(ctx, apr, dbData.Rsr, dbData.Ddb, apr.Contains(cli.ForceFlag), apr.Contains(cli.SetUpstreamFlag), pushAutoSetUpRemote) + if err != nil { + return cmdFailure, err + } + remoteDB, err := sess.Provider().GetRemoteDB(ctx, dbData.Ddb, opts.Remote, true) + if err != nil { + return 1, actions.HandleInitRemoteStorageClientErr(opts.Remote.Name, opts.Remote.Url, err) + } + + tmpDir, err := dbData.Rsw.TempTableFilesDir() + if err != nil { + return cmdFailure, err + } + err = actions.DoPush(ctx, dbData.Rsr, dbData.Rsw, dbData.Ddb, remoteDB, tmpDir, opts, runProgFuncs, stopProgFuncs) + if err != nil { + switch err { + case doltdb.ErrUpToDate: + return cmdSuccess, nil + case datas.ErrMergeNeeded: + return cmdFailure, fmt.Errorf("%w; the tip of your current branch is behind its remote counterpart", err) + default: + return cmdFailure, err + } + } + // TODO : set upstream should be persisted outside of session + return cmdSuccess, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go b/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go index 42f01db819..44bd7a82b0 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go @@ -15,16 +15,115 @@ package dprocedures import ( + "fmt" + "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/env/actions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" ) // doltReset is the stored procedure version of the function `dolt_reset`. func doltReset(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltReset(ctx, args) + res, err := doDoltReset(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltReset(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + + if len(dbName) == 0 { + return 1, fmt.Errorf("Empty database name.") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return 1, err + } + + dSess := dsess.DSessFromSess(ctx.Session) + dbData, ok := dSess.GetDbData(ctx, dbName) + + if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + apr, err := cli.CreateResetArgParser().Parse(args) + if err != nil { + return 1, err + } + + // Check if problems with args first. + if apr.ContainsAll(cli.HardResetParam, cli.SoftResetParam) { + return 1, fmt.Errorf("error: --%s and --%s are mutually exclusive options.", cli.HardResetParam, cli.SoftResetParam) + } + + provider := dSess.Provider() + db, err := provider.Database(ctx, dbName) + if err != nil { + return 1, err + } + + // Disallow manipulating any roots for read-only databases – changing the branch + // HEAD would allow changing data, and working set and index shouldn't ever have + // any contents for a read-only database. + if rodb, ok := db.(sql.ReadOnlyDatabase); ok { + if rodb.IsReadOnly() { + return 1, fmt.Errorf("unable to reset HEAD in read-only databases") + } + } + + // Get all the needed roots. + roots, ok := dSess.GetRoots(ctx, dbName) + if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + if apr.Contains(cli.HardResetParam) { + // Get the commitSpec for the branch if it exists + arg := "" + if apr.NArg() > 1 { + return 1, fmt.Errorf("--hard supports at most one additional param") + } else if apr.NArg() == 1 { + arg = apr.Arg(0) + } + + var newHead *doltdb.Commit + newHead, roots, err = actions.ResetHardTables(ctx, dbData, arg, roots) + if err != nil { + return 1, err + } + + // TODO: this overrides the transaction setting, needs to happen at commit, not here + if newHead != nil { + if err := dbData.Ddb.SetHeadToCommit(ctx, dbData.Rsr.CWBHeadRef(), newHead); err != nil { + return 1, err + } + } + + ws, err := dSess.WorkingSet(ctx, dbName) + if err != nil { + return 1, err + } + err = dSess.SetWorkingSet(ctx, dbName, ws.WithWorkingRoot(roots.Working).WithStagedRoot(roots.Staged).ClearMerge()) + if err != nil { + return 1, err + } + } else { + roots, err = actions.ResetSoftTables(ctx, dbData, apr, roots) + if err != nil { + return 1, err + } + + err = dSess.SetRoots(ctx, dbName, roots) + if err != nil { + return 1, err + } + } + + return 0, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_revert.go b/go/libraries/doltcore/sqle/dprocedures/dolt_revert.go index c87501d3f9..c5f7cfb3ae 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_revert.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_revert.go @@ -15,16 +15,123 @@ package dprocedures import ( - "github.com/dolthub/go-mysql-server/sql" + "fmt" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/go-mysql-server/sql" + "github.com/dolthub/go-mysql-server/sql/expression" + + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/merge" + "github.com/dolthub/dolt/go/libraries/doltcore/schema/typeinfo" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" ) // doltRevert is the stored procedure version of the function `revert` and `dolt_revert`. func doltRevert(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltRevert(ctx, nil, args) + res, err := doDoltRevert(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltRevert(ctx *sql.Context, args []string) (int, error) { + dbName := ctx.GetCurrentDatabase() + dSess := dsess.DSessFromSess(ctx.Session) + ddb, ok := dSess.GetDoltDB(ctx, dbName) + if !ok { + return 1, fmt.Errorf("dolt database could not be found") + } + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return 1, err + } + workingSet, err := dSess.WorkingSet(ctx, dbName) + if err != nil { + return 1, err + } + workingRoot := workingSet.WorkingRoot() + headCommit, err := dSess.GetHeadCommit(ctx, dbName) + if err != nil { + return 1, err + } + headRoot, err := headCommit.GetRootValue(ctx) + if err != nil { + return 1, err + } + headHash, err := headRoot.HashOf() + if err != nil { + return 1, err + } + workingHash, err := workingRoot.HashOf() + if err != nil { + return 1, err + } + if !headHash.Equal(workingHash) { + return 1, fmt.Errorf("you must commit any changes before using revert") + } + + headRef, err := dSess.CWBHeadRef(ctx, dbName) + if err != nil { + return 1, err + } + + apr, err := cli.CreateRevertArgParser().Parse(args) + if err != nil { + return 1, err + } + + commits := make([]*doltdb.Commit, apr.NArg()) + for i, revisionStr := range apr.Args { + commitSpec, err := doltdb.NewCommitSpec(revisionStr) + if err != nil { + return 1, err + } + commit, err := ddb.Resolve(ctx, commitSpec, headRef) + if err != nil { + return 1, err + } + commits[i] = commit + } + + dbState, ok, err := dSess.LookupDbState(ctx, dbName) + if err != nil { + return 1, err + } else if !ok { + return 1, fmt.Errorf("Could not load database %s", dbName) + } + + workingRoot, revertMessage, err := merge.Revert(ctx, ddb, workingRoot, headCommit, commits, dbState.EditOpts()) + if err != nil { + return 1, err + } + workingHash, err = workingRoot.HashOf() + if err != nil { + return 1, err + } + if !headHash.Equal(workingHash) { + err = dSess.SetRoot(ctx, dbName, workingRoot) + if err != nil { + return 1, err + } + stringType := typeinfo.StringDefaultType.ToSqlType() + + expressions := []sql.Expression{expression.NewLiteral("-a", stringType), expression.NewLiteral("-m", stringType), expression.NewLiteral(revertMessage, stringType)} + + author, hasAuthor := apr.GetValue(cli.AuthorParam) + if hasAuthor { + expressions = append(expressions, expression.NewLiteral("--author", stringType), expression.NewLiteral(author, stringType)) + } + + commitArgs, err := getDoltArgs(ctx, nil, expressions) + if err != nil { + return 1, err + } + _, err = doDoltCommit(ctx, commitArgs) + if err != nil { + return 1, err + } + } + return 0, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_verify_constraints.go b/go/libraries/doltcore/sqle/dprocedures/dolt_verify_constraints.go index 559a9dd762..54ba667c69 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_verify_constraints.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_verify_constraints.go @@ -17,14 +17,95 @@ package dprocedures import ( "github.com/dolthub/go-mysql-server/sql" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + "github.com/dolthub/dolt/go/libraries/doltcore/branch_control" + "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" + "github.com/dolthub/dolt/go/libraries/doltcore/merge" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" + "github.com/dolthub/dolt/go/libraries/utils/set" ) // doltVerifyConstraints is the stored procedure version of the function `constraints_verify`. func doltVerifyConstraints(ctx *sql.Context, args ...string) (sql.RowIter, error) { - res, err := dfunctions.DoDoltConstraintsVerify(ctx, args) + res, err := doDoltConstraintsVerify(ctx, args) if err != nil { return nil, err } return rowToIter(int64(res)), nil } + +func doDoltConstraintsVerify(ctx *sql.Context, args []string) (int, error) { + if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil { + return 1, err + } + dbName := ctx.GetCurrentDatabase() + dSess := dsess.DSessFromSess(ctx.Session) + workingSet, err := dSess.WorkingSet(ctx, dbName) + if err != nil { + return 1, err + } + workingRoot := workingSet.WorkingRoot() + headCommit, err := dSess.GetHeadCommit(ctx, dbName) + if err != nil { + return 1, err + } + h, err := headCommit.HashOf() + if err != nil { + return 1, err + } + + apr, err := cli.CreateVerifyConstraintsArgParser().Parse(args) + if err != nil { + return 1, err + } + + verifyAll := apr.Contains(cli.AllFlag) + outputOnly := apr.Contains(cli.OutputOnlyFlag) + + var comparingRoot *doltdb.RootValue + if verifyAll { + comparingRoot, err = doltdb.EmptyRootValue(ctx, workingRoot.VRW(), workingRoot.NodeStore()) + if err != nil { + return 1, err + } + } else { + comparingRoot, err = headCommit.GetRootValue(ctx) + if err != nil { + return 1, err + } + } + + tableSet := set.NewStrSet(nil) + for _, val := range apr.Args { + _, tableName, ok, err := workingRoot.GetTableInsensitive(ctx, val) + if err != nil { + return 1, err + } + if !ok { + return 1, sql.ErrTableNotFound.New(tableName) + } + tableSet.Add(tableName) + } + + newRoot, tablesWithViolations, err := merge.AddForeignKeyViolations(ctx, workingRoot, comparingRoot, tableSet, h) + if err != nil { + return 1, err + } + + if tablesWithViolations.Size() == 0 { + // no violations were found + return 0, nil + } + + // violations were found + + if !outputOnly { + err = dSess.SetRoot(ctx, dbName, newRoot) + if err != nil { + return 1, err + } + return 1, nil + } + + return 1, nil +} diff --git a/go/libraries/doltcore/sqle/dprocedures/init.go b/go/libraries/doltcore/sqle/dprocedures/init.go index c8fa98b4df..03270a508b 100644 --- a/go/libraries/doltcore/sqle/dprocedures/init.go +++ b/go/libraries/doltcore/sqle/dprocedures/init.go @@ -24,6 +24,7 @@ var DoltProcedures = []sql.ExternalStoredProcedureDetails{ {Name: "dolt_clean", Schema: int64Schema("status"), Function: doltClean}, {Name: "dolt_clone", Schema: int64Schema("status"), Function: doltClone}, {Name: "dolt_commit", Schema: stringSchema("hash"), Function: doltCommit}, + {Name: "dolt_commit_hash_out", Schema: stringSchema("hash"), Function: doltCommitHashOut}, {Name: "dolt_conflicts_resolve", Schema: int64Schema("status"), Function: doltConflictsResolve}, {Name: "dolt_fetch", Schema: int64Schema("success"), Function: doltFetch}, {Name: "dolt_gc", Schema: int64Schema("success"), Function: doltGC}, diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index 877dd66138..56025df06a 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -92,15 +92,19 @@ var ViewsWithAsOfScriptTest = queries.ScriptTest{ var ShowCreateTableAsOfScriptTest = queries.ScriptTest{ Name: "Show create table as of", SetUpScript: []string{ + "set @Commit0 = '';", + "set @Commit1 = '';", + "set @Commit2 = '';", + "set @Commit3 = '';", "set @Commit0 = hashof('main');", "create table a (pk int primary key, c1 int);", "call dolt_add('.');", - "set @Commit1 = dolt_commit('-am', 'creating table a');", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table a');", "alter table a add column c2 varchar(20);", - "set @Commit2 = dolt_commit('-am', 'adding column c2');", + "call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2');", "alter table a drop column c1;", "alter table a add constraint unique_c2 unique(c2);", - "set @Commit3 = dolt_commit('-am', 'dropping column c1');", + "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -160,14 +164,18 @@ var ShowCreateTableAsOfScriptTest = queries.ScriptTest{ var DescribeTableAsOfScriptTest = queries.ScriptTest{ Name: "Describe table as of", SetUpScript: []string{ - "set @Commit0 = dolt_commit('--allow-empty', '-m', 'before creating table a');", + "set @Commit0 = '';", + "set @Commit1 = '';", + "set @Commit2 = '';", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit0, '--allow-empty', '-m', 'before creating table a');", "create table a (pk int primary key, c1 int);", "call dolt_add('.');", - "set @Commit1 = dolt_commit('-am', 'creating table a');", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table a');", "alter table a add column c2 varchar(20);", - "set @Commit2 = dolt_commit('-am', 'adding column c2');", + "call dolt_commit_hash_out(@Commit2, '-am', 'adding column c2');", "alter table a drop column c1;", - "set @Commit3 = dolt_commit('-am', 'dropping column c1');", + "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c1');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -509,9 +517,9 @@ var DoltScripts = []queries.ScriptTest{ "create table a (pk int primary key, c1 int)", "call DOLT_ADD('.')", "insert into a values (1,1), (2,2), (3,3)", - "select DOLT_COMMIT('-a', '-m', 'first commit')", + "CALL DOLT_COMMIT('-a', '-m', 'first commit')", "insert into a values (4,4), (5,5), (6,6)", - "select DOLT_COMMIT('-a', '-m', 'second commit')", + "CALL DOLT_COMMIT('-a', '-m', 'second commit')", "set @second_commit = (select commit_hash from dolt_log order by date desc limit 1)", "set @first_commit = (select commit_hash from dolt_log order by date desc limit 1,1)", }, @@ -615,13 +623,15 @@ var DoltScripts = []queries.ScriptTest{ { Name: "Prepared ASOF", SetUpScript: []string{ + "set @Commit1 = '';", + "set @Commit2 = '';", "create table test (pk int primary key, c1 int)", "call dolt_add('.')", "insert into test values (0,0), (1,1);", - "set @Commit1 = dolt_commit('-am', 'creating table');", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table');", "call dolt_branch('-c', 'main', 'newb')", "alter table test add column c2 int;", - "set @Commit2 = dolt_commit('-am', 'alter table');", + "call dolt_commit_hash_out(@Commit2, '-am', 'alter table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -761,9 +771,9 @@ var DoltUserPrivTests = []queries.UserPrivilegeTest{ "CREATE TABLE mydb.test (pk BIGINT PRIMARY KEY);", "CREATE TABLE mydb.test2 (pk BIGINT PRIMARY KEY);", "CALL DOLT_ADD('.')", - "SELECT DOLT_COMMIT('-am', 'creating tables test and test2');", + "CALL DOLT_COMMIT('-am', 'creating tables test and test2');", "INSERT INTO mydb.test VALUES (1);", - "SELECT DOLT_COMMIT('-am', 'inserting into test');", + "CALL DOLT_COMMIT('-am', 'inserting into test');", "CREATE USER tester@localhost;", }, Assertions: []queries.UserPrivilegeTestAssertion{ @@ -1016,7 +1026,8 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (n int, c varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1031,13 +1042,16 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table foo1 (n int, de varchar(20));", "insert into foo1 values (1, 'Ein'), (2, 'Zwei'), (3, 'Drei');", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'inserting into foo1', '--date', '2022-08-06T12:00:00');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'inserting into foo1', '--date', '2022-08-06T12:00:00');", "update foo1 set de='Eins' where n=1;", - "set @Commit2 = dolt_commit('-am', 'updating data in foo1', '--date', '2022-08-06T12:00:01');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'updating data in foo1', '--date', '2022-08-06T12:00:01');", "insert into foo1 values (4, 'Vier');", - "set @Commit3 = dolt_commit('-am', 'inserting data in foo1', '--date', '2022-08-06T12:00:02');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting data in foo1', '--date', '2022-08-06T12:00:02');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1064,21 +1078,26 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t1 (n int primary key, de varchar(20));", "call dolt_add('.')", "insert into t1 values (1, 'Eins'), (2, 'Zwei'), (3, 'Drei');", - "set @Commit1 = dolt_commit('-am', 'inserting into t1', '--date', '2022-08-06T12:00:01');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'inserting into t1', '--date', '2022-08-06T12:00:01');", "alter table t1 add column fr varchar(20);", "insert into t1 values (4, 'Vier', 'Quatre');", - "set @Commit2 = dolt_commit('-am', 'adding column and inserting data in t1', '--date', '2022-08-06T12:00:02');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'adding column and inserting data in t1', '--date', '2022-08-06T12:00:02');", "update t1 set fr='Un' where n=1;", "update t1 set fr='Deux' where n=2;", - "set @Commit3 = dolt_commit('-am', 'updating data in t1', '--date', '2022-08-06T12:00:03');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'updating data in t1', '--date', '2022-08-06T12:00:03');", "update t1 set de=concat(de, ', meine herren') where n>1;", - "set @Commit4 = dolt_commit('-am', 'be polite when you address a gentleman', '--date', '2022-08-06T12:00:04');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'be polite when you address a gentleman', '--date', '2022-08-06T12:00:04');", "delete from t1 where n=2;", - "set @Commit5 = dolt_commit('-am', 'we don''t need the number 2', '--date', '2022-08-06T12:00:05');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'we don''t need the number 2', '--date', '2022-08-06T12:00:05');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1132,9 +1151,11 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t1 (pk int primary key, c int);", "call dolt_add('.')", "insert into t1 values (1,2), (3,4)", - "set @Commit1 = dolt_commit('-am', 'initial table');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'initial table');", "insert into t1 values (5,6), (7,8)", - "set @Commit2 = dolt_commit('-am', 'two more rows');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'two more rows');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1215,12 +1236,15 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t1 (pk int primary key, c int);", "call dolt_add('.')", "insert into t1 values (1,2), (3,4)", - "set @Commit1 = dolt_commit('-am', 'initial table');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'initial table');", "insert into t1 values (5,6), (7,8)", - "set @Commit2 = dolt_commit('-am', 'two more rows');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'two more rows');", "insert into t1 values (9,10), (11,12)", "create index t1_c on t1(c)", - "set @Commit2 = dolt_commit('-am', 'two more rows and an index');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'two more rows and an index');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1286,13 +1310,16 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 varchar(20));", "call dolt_add('.')", "insert into t values (1, 2, '3'), (4, 5, '6');", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c2;", - "set @Commit2 = DOLT_COMMIT('-am', 'dropping column c2');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c2');", "alter table t rename column c1 to c2;", - "set @Commit3 = DOLT_COMMIT('-am', 'renaming c1 to c2');", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'renaming c1 to c2');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1326,9 +1353,11 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 varchar(20));", "call dolt_add('.')", "insert into t values (1, 2, '3'), (4, 5, '6');", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t modify column c2 int;", - "set @Commit2 = DOLT_COMMIT('-am', 'changed type of c2');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'changed type of c2');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1352,11 +1381,13 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 varchar(20));", "call dolt_add('.')", "insert into t values (1, 2, '3'), (4, 5, '6');", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t rename to t2;", "call dolt_add('.')", - "set @Commit2 = DOLT_COMMIT('-am', 'renaming table to t2');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'renaming table to t2');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1379,14 +1410,17 @@ var HistorySystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 varchar(20));", "call dolt_add('.')", "insert into t values (1, 2, '3'), (4, 5, '6');", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "drop table t;", - "set @Commit2 = DOLT_COMMIT('-am', 'dropping table t');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping table t');", "create table t (pk int primary key, c1 int);", "call dolt_add('.')", - "set @Commit3 = DOLT_COMMIT('-am', 'recreating table t');", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'recreating table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1691,7 +1725,8 @@ var DoltBranchScripts = []queries.ScriptTest{ SetUpScript: []string{ "create table a (x int)", "call dolt_add('.')", - "set @commit1 = (select DOLT_COMMIT('-am', 'add table a'));", + "SET @commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@commit1, '-am', 'add table a');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1813,10 +1848,12 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1986,14 +2023,17 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", "call dolt_checkout('-b', 'new-branch')", "insert into t values (3, 'three', 'four');", - "set @Commit3 = dolt_commit('-am', 'inserting into t again');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t again');", "call dolt_checkout('main')", }, Assertions: []queries.ScriptTestAssertion{ @@ -2026,7 +2066,7 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ Expected: []sql.Row{{3}}, }, { - Query: "SELECT count(*) from dolt_log('main') join dolt_diff(@Commit1, @Commit2, 't') where commit_hash = to_commit;", + Query: "SELECT count(*) from dolt_log('main') join dolt_diff(@Commit1, @Commit2, 't') where commit_hash = to_commit;", Expected: []sql.Row{{2}}, }, }, @@ -2036,20 +2076,25 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.');", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t 2');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t 2');", "call dolt_checkout('-b', 'new-branch');", "insert into t values (3, 'three', 'four');", - "set @Commit3 = dolt_commit('-am', 'inserting into t 3');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t 3');", "insert into t values (4, 'four', 'five');", - "set @Commit4 = dolt_commit('-am', 'inserting into t 4');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting into t 4');", "call dolt_checkout('main');", "insert into t values (5, 'five', 'six');", - "set @Commit5 = dolt_commit('-am', 'inserting into t 5');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'inserting into t 5');", }, /* Commit graph: 3 - 4 (new-branch) @@ -2136,14 +2181,17 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", "call dolt_checkout('-b', 'new-branch')", "insert into t values (3, 'three', 'four');", - "set @Commit3 = dolt_commit('-am', 'inserting into t again', '--author', 'John Doe ');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t again', '--author', 'John Doe ');", "call dolt_checkout('main')", }, Assertions: []queries.ScriptTestAssertion{ @@ -2175,20 +2223,25 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.');", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t 2');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t 2');", "call dolt_checkout('-b', 'new-branch');", "insert into t values (3, 'three', 'four');", - "set @Commit3 = dolt_commit('-am', 'inserting into t 3', '--author', 'John Doe ');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into t 3', '--author', 'John Doe ');", "insert into t values (4, 'four', 'five');", - "set @Commit4 = dolt_commit('-am', 'inserting into t 4', '--author', 'John Doe ');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting into t 4', '--author', 'John Doe ');", "call dolt_checkout('main');", "insert into t values (5, 'five', 'six');", - "set @Commit5 = dolt_commit('-am', 'inserting into t 5');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'inserting into t 5');", }, /* Commit graph: 3 - 4 (new-branch) @@ -2266,21 +2319,25 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ }, }, }, - { + //TODO: figure out how we were returning a commit from the function + /*{ Name: "min parents, merges, show parents, decorate", SetUpScript: []string{ "create table t (pk int primary key, c1 int);", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "call dolt_checkout('-b', 'branch1')", "insert into t values(0,0);", - "set @Commit2 = dolt_commit('-am', 'inserting 0,0');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting 0,0');", "call dolt_checkout('main')", "call dolt_checkout('-b', 'branch2')", "insert into t values(1,1);", - "set @Commit3 = dolt_commit('-am', 'inserting 1,1');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1,1');", "call dolt_checkout('main')", "call dolt_merge('branch1')", // fast-forward merge @@ -2349,7 +2406,7 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{ Expected: []sql.Row{{true, true, "HEAD -> branch1"}}, }, }, - }, + },*/ } var LargeJsonObjectScriptTests = []queries.ScriptTest{ diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go index af059cbde0..0a99f49fc1 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go @@ -29,7 +29,8 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -51,10 +52,12 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "update t set c2=0 where pk=1", - "set @Commit2 = (select DOLT_COMMIT('-am', 'modifying row'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'modifying row');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -75,10 +78,12 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "delete from t where pk=1", - "set @Commit2 = (select DOLT_COMMIT('-am', 'modifying row'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'modifying row');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -100,15 +105,18 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "drop table t;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping table t'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping table t');", "create table t (pk int primary key, c int);", "call dolt_add('.')", "insert into t values (100, 200), (300, 400);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'recreating table t'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'recreating table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -131,10 +139,12 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c1;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -164,14 +174,17 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", "alter table t add column c int;", "insert into t values (100, 101);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'inserting into t'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -207,14 +220,17 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c1;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c1'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c1');", "alter table t rename column c2 to c1;", "insert into t values (100, 101);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'inserting into t'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -295,14 +311,17 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", "alter table t add column c varchar(20);", "insert into t values (100, '101');", - "set @Commit3 = (select DOLT_COMMIT('-am', 're-adding column c'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -337,14 +356,17 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c varchar(20));", "call dolt_add('.')", "insert into t values (1, 'two'), (3, 'four');", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", "alter table t add column c int;", "insert into t values (100, 101);", - "set @Commit3 = (select DOLT_COMMIT('-am', 're-adding column c'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -386,18 +408,22 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int);", "call dolt_add('.')", "insert into t values (1, 2);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t rename column c1 to c2;", "insert into t values (3, 4);", - "set @Commit2 = (select DOLT_COMMIT('-am', 'renaming c1 to c2'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'renaming c1 to c2');", "alter table t drop column c2;", - "set @Commit3 = (select DOLT_COMMIT('-am', 'dropping column c2'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'dropping column c2');", "alter table t add column c2 int;", "insert into t values (100, '101');", - "set @Commit4 = (select DOLT_COMMIT('-am', 'recreating column c2'));", + "set @Commit4 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'recreating column c2');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -437,17 +463,21 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop primary key;", "insert into t values (5, 6);", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping primary key'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping primary key');", "alter table t add primary key (c1);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'adding primary key'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'adding primary key');", "insert into t values (7, 8);", - "set @Commit4 = (select DOLT_COMMIT('-am', 'adding more data'));", + "set @Commit4 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'adding more data');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -489,11 +519,14 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'first commit'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'first commit');", "insert into t values (7, 8, 9);", - "set @Commit2 = (select DOLT_COMMIT('-am', 'second commit'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'second commit');", "update t set c1 = 0 where pk > 5;", - "set @Commit3 = (select DOLT_COMMIT('-am', 'third commit'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'third commit');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -522,11 +555,14 @@ var DiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk1 int, pk2 int, c1 int, primary key (pk1, pk2));", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'first commit'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'first commit');", "insert into t values (7, 8, 9);", - "set @Commit2 = (select DOLT_COMMIT('-am', 'second commit'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'second commit');", "update t set c1 = 0 where pk1 > 5;", - "set @Commit3 = (select DOLT_COMMIT('-am', 'third commit'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'third commit');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -633,10 +669,12 @@ var DiffTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -741,19 +779,23 @@ var DiffTableFunctionScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two');", - "set @Commit2 = dolt_commit('-am', 'inserting into table t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into table t');", "create table t2 (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", "insert into t2 values(100, 'hundred', 'hundert');", - "set @Commit3 = dolt_commit('-am', 'inserting into table t2');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into table t2');", "insert into t values(2, 'two', 'three'), (3, 'three', 'four');", "update t set c1='uno', c2='dos' where pk=1;", - "set @Commit4 = dolt_commit('-am', 'inserting into table t');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting into table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -819,7 +861,8 @@ inner join t on to_pk = t.pk;`, "create table t (pk int primary key, c1 text, c2 text);", "call dolt_add('.')", "insert into t values (1, 'one', 'two'), (2, 'three', 'four');", - "set @Commit1 = dolt_commit('-am', 'inserting two rows into table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'inserting two rows into table t');", "insert into t values (3, 'five', 'six');", "delete from t where pk = 2", @@ -893,24 +936,30 @@ inner join t on to_pk = t.pk;`, SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two');", - "set @Commit2 = dolt_commit('-am', 'inserting row 1 into t in main');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting row 1 into t in main');", - "select dolt_checkout('-b', 'branch1');", + "CALL DOLT_checkout('-b', 'branch1');", "alter table t drop column c2;", - "set @Commit3 = dolt_commit('-am', 'dropping column c2 in branch1');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2 in branch1');", "delete from t where pk=1;", - "set @Commit4 = dolt_commit('-am', 'deleting row 1 in branch1');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'deleting row 1 in branch1');", "insert into t values (2, 'two');", - "set @Commit5 = dolt_commit('-am', 'inserting row 2 in branch1');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'inserting row 2 in branch1');", - "select dolt_checkout('main');", + "CALL DOLT_checkout('main');", "insert into t values (2, 'two', 'three');", - "set @Commit6 = dolt_commit('-am', 'inserting row 2 in main');", + "set @Commit6 = '';", + "call dolt_commit_hash_out(@Commit6, '-am', 'inserting row 2 in main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -990,18 +1039,22 @@ inner join t on to_pk = t.pk;`, SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", "alter table t drop column c2;", - "set @Commit3 = dolt_commit('-am', 'dropping column c2');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2');", "alter table t add column c2 varchar(20);", "insert into t values (3, 'three', 'four');", "update t set c2='foo' where pk=1;", - "set @Commit4 = dolt_commit('-am', 'adding column c2, inserting, and updating data');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'adding column c2, inserting, and updating data');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1050,21 +1103,26 @@ inner join t on to_pk = t.pk;`, SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 int);", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', -1), (2, 'two', -2);", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", "alter table t rename column c2 to c3;", - "set @Commit3 = dolt_commit('-am', 'renaming column c2 to c3');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'renaming column c2 to c3');", "insert into t values (3, 'three', -3);", "update t set c3=1 where pk=1;", - "set @Commit4 = dolt_commit('-am', 'inserting and updating data');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');", "alter table t rename column c3 to c2;", "insert into t values (4, 'four', -4);", - "set @Commit5 = dolt_commit('-am', 'renaming column c3 to c2, and inserting data');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'renaming column c3 to c2, and inserting data');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1119,21 +1177,26 @@ inner join t on to_pk = t.pk;`, SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'asdf'), (2, 'two', '2');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", "alter table t drop column c2;", - "set @Commit3 = dolt_commit('-am', 'dropping column c2');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2');", "insert into t values (3, 'three');", "update t set c1='fdsa' where pk=1;", - "set @Commit4 = dolt_commit('-am', 'inserting and updating data');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');", "alter table t add column c2 int;", "insert into t values (4, 'four', -4);", - "set @Commit5 = dolt_commit('-am', 'adding column c2, and inserting data');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'adding column c2, and inserting data');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1288,10 +1351,12 @@ var DiffSummaryTableFunctionScriptTests = []queries.ScriptTest{ SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1368,25 +1433,30 @@ var DiffSummaryTableFunctionScriptTests = []queries.ScriptTest{ Name: "basic case with single table", SetUpScript: []string{ "set @Commit0 = HashOf('HEAD');", - "set @Commit1 = dolt_commit('--allow-empty', '-m', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');", // create table t only "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit2 = dolt_commit('-am', 'creating table t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');", // insert 1 row into t "insert into t values(1, 'one', 'two');", - "set @Commit3 = dolt_commit('-am', 'inserting 1 into table t');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');", // insert 2 rows into t and update two cells "insert into t values(2, 'two', 'three'), (3, 'three', 'four');", "update t set c1='uno', c2='dos' where pk=1;", - "set @Commit4 = dolt_commit('-am', 'inserting 2 into table t');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');", // drop table t only "drop table t;", - "set @Commit5 = dolt_commit('-am', 'drop table t');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1433,25 +1503,30 @@ inner join t as of @Commit3 on rows_unmodified = t.pk;`, Name: "basic case with single keyless table", SetUpScript: []string{ "set @Commit0 = HashOf('HEAD');", - "set @Commit1 = dolt_commit('--allow-empty', '-m', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '--allow-empty', '-m', 'creating table t');", // create table t only "create table t (id int, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit2 = dolt_commit('-am', 'creating table t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'creating table t');", // insert 1 row into t "insert into t values(1, 'one', 'two');", - "set @Commit3 = dolt_commit('-am', 'inserting 1 into table t');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting 1 into table t');", // insert 2 rows into t and update two cells "insert into t values(2, 'two', 'three'), (3, 'three', 'four');", "update t set c1='uno', c2='dos' where id=1;", - "set @Commit4 = dolt_commit('-am', 'inserting 2 into table t');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting 2 into table t');", // drop table t only "drop table t;", - "set @Commit5 = dolt_commit('-am', 'drop table t');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'drop table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1500,24 +1575,28 @@ inner join t as of @Commit3 on rows_unmodified = t.pk;`, "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "insert into t values(1, 'one', 'two');", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'inserting into table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'inserting into table t');", // add table t2 with 1 row "create table t2 (pk int primary key, c1 varchar(20), c2 varchar(20));", "insert into t2 values(100, 'hundred', 'hundert');", "call dolt_add('.')", - "set @Commit2 = dolt_commit('-am', 'inserting into table t2');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into table t2');", // changes on both tables "insert into t values(2, 'two', 'three'), (3, 'three', 'four'), (4, 'four', 'five');", "update t set c1='uno', c2='dos' where pk=1;", "insert into t2 values(101, 'hundred one', 'one');", - "set @Commit3 = dolt_commit('-am', 'inserting into table t');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting into table t');", // changes on both tables "delete from t where c2 = 'four';", "update t2 set c2='zero' where pk=100;", - "set @Commit4 = dolt_commit('-am', 'inserting into table t');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting into table t');", // create keyless table "create table keyless (id int);", @@ -1557,7 +1636,8 @@ inner join t as of @Commit3 on rows_unmodified = t.pk;`, "create table t (pk int primary key, c1 text, c2 text);", "call dolt_add('.')", "insert into t values (1, 'one', 'two'), (2, 'three', 'four');", - "set @Commit1 = dolt_commit('-am', 'inserting two rows into table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'inserting two rows into table t');", "insert into t values (3, 'five', 'six');", "delete from t where pk = 2", @@ -1611,28 +1691,35 @@ inner join t as of @Commit3 on rows_unmodified = t.pk;`, SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', 'two');", - "set @Commit2 = dolt_commit('-am', 'inserting row 1 into t in main');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting row 1 into t in main');", - "select dolt_checkout('-b', 'branch1');", + "CALL DOLT_checkout('-b', 'branch1');", "alter table t drop column c2;", - "set @Commit3 = dolt_commit('-am', 'dropping column c2 in branch1');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'dropping column c2 in branch1');", "delete from t where pk=1;", - "set @Commit4 = dolt_commit('-am', 'deleting row 1 in branch1');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'deleting row 1 in branch1');", "insert into t values (2, 'two');", - "set @Commit5 = dolt_commit('-am', 'inserting row 2 in branch1');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'inserting row 2 in branch1');", - "select dolt_checkout('main');", + "CALL DOLT_checkout('main');", "insert into t values (2, 'two', 'three');", - "set @Commit6 = dolt_commit('-am', 'inserting row 2 in main');", + "set @Commit6 = '';", + "call dolt_commit_hash_out(@Commit6, '-am', 'inserting row 2 in main');", "create table newtable (pk int primary key);", "insert into newtable values (1), (2);", - "set @Commit7 = dolt_commit('-Am', 'new table newtable');", + "set @Commit7 = '';", + "call dolt_commit_hash_out(@Commit7, '-Am', 'new table newtable');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1714,21 +1801,25 @@ inner join t as of @Commit3 on rows_unmodified = t.pk;`, "create table t (pk int primary key, c1 varchar(20), c2 varchar(20));", "call dolt_add('.');", "insert into t values (1, 'one', 'two'), (2, 'two', 'three');", - "set @Commit1 = dolt_commit('-am', 'inserting row 1, 2 into t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'inserting row 1, 2 into t');", // drop 1 column and add 1 row "alter table t drop column c2;", - "set @Commit2 = dolt_commit('-am', 'dropping column c2');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'dropping column c2');", // drop 1 column and add 1 row "insert into t values (3, 'three');", - "set @Commit3 = dolt_commit('-am', 'inserting row 3');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'inserting row 3');", // add 1 column and 1 row and update "alter table t add column c2 varchar(20);", "insert into t values (4, 'four', 'five');", "update t set c2='foo' where pk=1;", - "set @Commit4 = dolt_commit('-am', 'adding column c2, inserting, and updating data');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'adding column c2, inserting, and updating data');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1758,21 +1849,26 @@ inner join t as of @Commit3 on rows_unmodified = t.pk;`, SetUpScript: []string{ "create table t (pk int primary key, c1 varchar(20), c2 int);", "call dolt_add('.')", - "set @Commit1 = dolt_commit('-am', 'creating table t');", + "set @Commit1 = '';", + "call dolt_commit_hash_out(@Commit1, '-am', 'creating table t');", "insert into t values(1, 'one', -1), (2, 'two', -2);", - "set @Commit2 = dolt_commit('-am', 'inserting into t');", + "set @Commit2 = '';", + "call dolt_commit_hash_out(@Commit2, '-am', 'inserting into t');", "alter table t rename column c2 to c3;", - "set @Commit3 = dolt_commit('-am', 'renaming column c2 to c3');", + "set @Commit3 = '';", + "call dolt_commit_hash_out(@Commit3, '-am', 'renaming column c2 to c3');", "insert into t values (3, 'three', -3);", "update t set c3=1 where pk=1;", - "set @Commit4 = dolt_commit('-am', 'inserting and updating data');", + "set @Commit4 = '';", + "call dolt_commit_hash_out(@Commit4, '-am', 'inserting and updating data');", "alter table t rename column c3 to c2;", "insert into t values (4, 'four', -4);", - "set @Commit5 = dolt_commit('-am', 'renaming column c3 to c2, and inserting data');", + "set @Commit5 = '';", + "call dolt_commit_hash_out(@Commit5, '-am', 'renaming column c3 to c2, and inserting data');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1961,7 +2057,8 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ "call dolt_add('.')", "insert into regularTable values (1, 2, 3), (2, 3, 4);", "insert into droppedTable values (1, 2, 3), (2, 3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y');", // changeSet: STAGED; data change: false; schema change: true "create table addedTable (a int primary key, b int, c int);", @@ -2025,19 +2122,23 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ "create table y (a int primary key, b int, c int);", "call dolt_add('.')", "insert into x values (1, 2, 3), (2, 3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y');", "create table z (a int primary key, b int, c int);", "call dolt_add('.')", "insert into z values (100, 101, 102);", - "set @Commit2 = (select DOLT_COMMIT('-am', 'Creating tables z'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z');", "insert into y values (-1, -2, -3), (-2, -3, -4);", "insert into z values (101, 102, 103);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'Inserting into tables y and z'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Inserting into tables y and z');", "alter table y add column d int;", - "set @Commit4 = (select DOLT_COMMIT('-am', 'Modify schema of table y'));", + "set @Commit4 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'Modify schema of table y');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2065,21 +2166,25 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ "create table y (a int primary key, b int, c int)", "call dolt_add('.')", "insert into x values (1, 2, 3), (2, 3, 4)", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'))", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')", "create table z (a int primary key, b int, c int)", "call dolt_add('.')", "insert into z values (100, 101, 102)", - "set @Commit2 = (select DOLT_COMMIT('-am', 'Creating tables z'))", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z')", "rename table x to x1", "call dolt_add('.')", "insert into x1 values (1000, 1001, 1002);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'Renaming table x to x1 and inserting data'))", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Renaming table x to x1 and inserting data')", "rename table x1 to x2", "call dolt_add('.')", - "set @Commit4 = (select DOLT_COMMIT('-am', 'Renaming table x1 to x2'))", + "set @Commit4 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'Renaming table x1 to x2')", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2111,13 +2216,16 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ "create table y (a int primary key, b int, c int)", "call dolt_add('.')", "insert into x values (1, 2, 3), (2, 3, 4)", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'))", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')", "drop table x", - "set @Commit2 = (select DOLT_COMMIT('-am', 'Dropping non-empty table x'))", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Dropping non-empty table x')", "drop table y", - "set @Commit3 = (select DOLT_COMMIT('-am', 'Dropping empty table y'))", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Dropping empty table y')", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2145,12 +2253,13 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ "create table y (a int primary key, b int, c int)", "call dolt_add('.')", "insert into x values (1, 2, 3), (2, 3, 4)", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'))", - - "set @Commit2 = (select DOLT_COMMIT('--allow-empty', '-m', 'Empty!'))", - + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '--allow-empty', '-m', 'Empty!')", "insert into y values (-1, -2, -3), (-2, -3, -4)", - "set @Commit3 = (select DOLT_COMMIT('-am', 'Inserting into table y'))", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Inserting into table y')", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2174,22 +2283,25 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ { Name: "includes commits from all branches", SetUpScript: []string{ - "select dolt_checkout('-b', 'branch1')", + "CALL DOLT_checkout('-b', 'branch1')", "create table x (a int primary key, b int, c int)", "create table y (a int primary key, b int, c int)", "call dolt_add('.')", "insert into x values (1, 2, 3), (2, 3, 4)", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'))", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')", - "select dolt_checkout('-b', 'branch2')", + "CALL DOLT_checkout('-b', 'branch2')", "create table z (a int primary key, b int, c int)", "call dolt_add('.')", "insert into z values (100, 101, 102)", - "set @Commit2 = (select DOLT_COMMIT('-am', 'Creating tables z'))", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z')", "insert into y values (-1, -2, -3), (-2, -3, -4)", "insert into z values (101, 102, 103)", - "set @Commit3 = (select DOLT_COMMIT('-am', 'Inserting into tables y and z'))", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Inserting into tables y and z')", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2216,21 +2328,24 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{ { Name: "merge history handling", SetUpScript: []string{ - "select dolt_checkout('-b', 'branch1')", + "CALL DOLT_checkout('-b', 'branch1')", "create table x (a int primary key, b int, c int)", "create table y (a int primary key, b int, c int)", "call dolt_add('.')", "insert into x values (1, 2, 3), (2, 3, 4)", - "set @Commit1 = (select DOLT_COMMIT('-am', 'Creating tables x and y'))", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'Creating tables x and y')", - "select dolt_checkout('-b', 'branch2')", + "CALL DOLT_checkout('-b', 'branch2')", "create table z (a int primary key, b int, c int)", "call dolt_add('.')", "insert into z values (100, 101, 102)", - "set @Commit2 = (select DOLT_COMMIT('-am', 'Creating tables z'))", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'Creating tables z')", - "select DOLT_MERGE('branch1', '--no-commit')", - "set @Commit3 = (select DOLT_COMMIT('-am', 'Merging branch1 into branch2'))", + "CALL DOLT_MERGE('branch1', '--no-commit')", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'Merging branch1 into branch2')", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2260,7 +2375,8 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2284,19 +2400,24 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "update t set c2=0 where pk=1", - "set @Commit2 = (select DOLT_COMMIT('-am', 'modifying row'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'modifying row');", "update t set c2=-1 where pk=1", - "set @Commit3 = (select DOLT_COMMIT('-am', 'modifying row'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'modifying row');", "update t set c2=-2 where pk=1", - "set @Commit4 = (select DOLT_COMMIT('-am', 'modifying row'));", + "set @Commit4 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'modifying row');", "delete from t where pk=1", - "set @Commit5 = (select DOLT_COMMIT('-am', 'modifying row'));", + "set @Commit5 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit5, '-am', 'modifying row');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2340,10 +2461,12 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c1;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2370,14 +2493,17 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", "alter table t add column c int;", "insert into t values (100, 101);", - "set @Commit3 = (select DOLT_COMMIT('-am', 'inserting into t'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2410,14 +2536,17 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int, c2 int);", "call dolt_add('.')", "insert into t values (1, 2, 3), (4, 5, 6);", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c1;", - "set @Commit2 = DOLT_COMMIT('-am', 'dropping column c1');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c1');", "alter table t rename column c2 to c1;", "insert into t values (100, 101);", - "set @Commit3 = DOLT_COMMIT('-am', 'inserting into t');", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'inserting into t');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2453,14 +2582,17 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c;", - "set @Commit2 = DOLT_COMMIT('-am', 'dropping column c');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", "alter table t add column c varchar(20);", "insert into t values (100, '101');", - "set @Commit3 = DOLT_COMMIT('-am', 're-adding column c');", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2492,14 +2624,17 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c varchar(20));", "call dolt_add('.')", "insert into t values (1, 'two'), (3, 'four');", - "set @Commit1 = (select DOLT_COMMIT('-am', 'creating table t'));", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop column c;", - "set @Commit2 = (select DOLT_COMMIT('-am', 'dropping column c'));", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping column c');", "alter table t add column c int;", "insert into t values (100, 101);", - "set @Commit3 = (select DOLT_COMMIT('-am', 're-adding column c'));", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 're-adding column c');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -2537,17 +2672,21 @@ var CommitDiffSystemTableScriptTests = []queries.ScriptTest{ "create table t (pk int primary key, c1 int);", "call dolt_add('.')", "insert into t values (1, 2), (3, 4);", - "set @Commit1 = DOLT_COMMIT('-am', 'creating table t');", + "set @Commit1 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit1, '-am', 'creating table t');", "alter table t drop primary key;", "insert into t values (5, 6);", - "set @Commit2 = DOLT_COMMIT('-am', 'dropping primary key');", + "set @Commit2 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit2, '-am', 'dropping primary key');", "alter table t add primary key (c1);", - "set @Commit3 = DOLT_COMMIT('-am', 'adding primary key');", + "set @Commit3 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit3, '-am', 'adding primary key');", "insert into t values (7, 8);", - "set @Commit4 = DOLT_COMMIT('-am', 'adding more data');", + "set @Commit4 = '';", + "CALL DOLT_COMMIT_HASH_OUT(@Commit4, '-am', 'adding more data');", }, Assertions: []queries.ScriptTestAssertion{ { diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go index f1da7f4b8e..252977c3e1 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries_merge.go @@ -23,7 +23,7 @@ import ( "gopkg.in/src-d/go-errors.v1" "github.com/dolthub/dolt/go/libraries/doltcore/merge" - "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions" + "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dprocedures" "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" ) @@ -56,13 +56,13 @@ var MergeScripts = []queries.ScriptTest{ "call DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", "CALL DOLT_ADD('.');", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a ff');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", + "CALL DOLT_CHECKOUT('main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -79,7 +79,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'new-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'new-branch')", Expected: []sql.Row{{0}}, }, { @@ -95,12 +95,12 @@ var MergeScripts = []queries.ScriptTest{ "call DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a ff', '--date', '2022-08-06T12:00:01');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a ff', '--date', '2022-08-06T12:00:01');", + "CALL DOLT_CHECKOUT('main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -125,7 +125,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{"this is a no-ff"}}, // includes the merge commit created by no-ff }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", Expected: []sql.Row{{0}}, }, }, @@ -137,14 +137,14 @@ var MergeScripts = []queries.ScriptTest{ "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", + "CALL DOLT_CHECKOUT('main');", "INSERT INTO test VALUES (5),(6),(7);", - "SELECT DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:03');", + "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:03');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -176,14 +176,14 @@ var MergeScripts = []queries.ScriptTest{ "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", + "CALL DOLT_CHECKOUT('main');", "INSERT INTO test VALUES (5),(6),(7);", - "SELECT DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:03');", + "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:03');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -208,7 +208,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{"add some more values"}}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", ExpectedErr: dsess.ErrWorkingSetChanges, }, }, @@ -220,14 +220,14 @@ var MergeScripts = []queries.ScriptTest{ "call DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:01');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (1, 1);", "UPDATE test SET val=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:02');", + "CALL DOLT_CHECKOUT('main');", "UPDATE test SET val=1001 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'update a value', '--date', '2022-08-06T12:00:03');", + "CALL DOLT_COMMIT('-a', '-m', 'update a value', '--date', '2022-08-06T12:00:03');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -251,7 +251,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{"update a value"}}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", ExpectedErr: dsess.ErrWorkingSetChanges, }, { @@ -279,12 +279,12 @@ var MergeScripts = []queries.ScriptTest{ "call DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a ff');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", + "CALL DOLT_CHECKOUT('main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -312,12 +312,12 @@ var MergeScripts = []queries.ScriptTest{ "call DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a ff');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", + "CALL DOLT_CHECKOUT('main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -325,7 +325,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{1, 0}}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other')", + Query: "CALL DOLT_CHECKOUT('-b', 'other')", ExpectedErr: dsess.ErrWorkingSetChanges, }, { @@ -340,12 +340,12 @@ var MergeScripts = []queries.ScriptTest{ "CREATE TABLE test (pk int primary key)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a ff');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", + "CALL DOLT_CHECKOUT('main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -362,7 +362,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'new-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'new-branch')", Expected: []sql.Row{{0}}, }, { @@ -377,12 +377,12 @@ var MergeScripts = []queries.ScriptTest{ "CREATE TABLE test (pk int primary key)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a ff');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a ff');", + "CALL DOLT_CHECKOUT('main');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -407,7 +407,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{"this is a no-ff"}}, // includes the merge commit created by no-ff }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", Expected: []sql.Row{{0}}, }, }, @@ -418,14 +418,14 @@ var MergeScripts = []queries.ScriptTest{ "CREATE TABLE test (pk int primary key)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", + "CALL DOLT_CHECKOUT('main');", "INSERT INTO test VALUES (5),(6),(7);", - "SELECT DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", + "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -456,14 +456,14 @@ var MergeScripts = []queries.ScriptTest{ "CREATE TABLE test (pk int primary key)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0),(1),(2);", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1', '--date', '2022-08-06T12:00:00');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (3);", "UPDATE test SET pk=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit', '--date', '2022-08-06T12:00:01');", + "CALL DOLT_CHECKOUT('main');", "INSERT INTO test VALUES (5),(6),(7);", - "SELECT DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", + "CALL DOLT_COMMIT('-a', '-m', 'add some more values', '--date', '2022-08-06T12:00:02');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -483,7 +483,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{"add some more values"}}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", Expected: []sql.Row{{0}}, }, }, @@ -494,14 +494,14 @@ var MergeScripts = []queries.ScriptTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (1, 1);", "UPDATE test SET val=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", + "CALL DOLT_CHECKOUT('main');", "UPDATE test SET val=1001 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'update a value');", + "CALL DOLT_COMMIT('-a', '-m', 'update a value');", "set dolt_allow_commit_conflicts = on", }, Assertions: []queries.ScriptTestAssertion{ @@ -514,8 +514,8 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{1}}, }, { - Query: "SELECT DOLT_MERGE('--abort')", - Expected: []sql.Row{{0}}, + Query: "CALL DOLT_MERGE('--abort')", + Expected: []sql.Row{{0, 0}}, }, { Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", @@ -538,7 +538,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{}}, }, { - Query: "SELECT DOLT_MERGE('feature-branch')", + Query: "CALL DOLT_MERGE('feature-branch')", ExpectedErrStr: dsess.ErrUnresolvedConflictsCommit.Error(), }, { @@ -554,14 +554,14 @@ var MergeScripts = []queries.ScriptTest{ "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (1, 1);", "UPDATE test SET val=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", + "CALL DOLT_CHECKOUT('main');", "UPDATE test SET val=1001 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'update a value');", + "CALL DOLT_COMMIT('-a', '-m', 'update a value');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -577,8 +577,8 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{1}}, }, { - Query: "SELECT DOLT_MERGE('--abort')", - Expected: []sql.Row{{0}}, + Query: "CALL DOLT_MERGE('--abort')", + Expected: []sql.Row{{0, 0}}, }, { Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", @@ -597,7 +597,7 @@ var MergeScripts = []queries.ScriptTest{ Expected: []sql.Row{{0, 1001}}, }, { - Query: "SELECT DOLT_CHECKOUT('-b', 'other-branch')", + Query: "CALL DOLT_CHECKOUT('-b', 'other-branch')", Expected: []sql.Row{{0}}, }, }, @@ -609,18 +609,18 @@ var MergeScripts = []queries.ScriptTest{ "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", "SET autocommit = 0", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (1, 1);", "UPDATE test SET val=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", + "CALL DOLT_CHECKOUT('main');", "UPDATE test SET val=1001 WHERE pk=0;", }, Assertions: []queries.ScriptTestAssertion{ { Query: "CALL DOLT_MERGE('feature-branch', '-m', 'this is a merge')", - ExpectedErr: dfunctions.ErrUncommittedChanges, + ExpectedErr: dprocedures.ErrUncommittedChanges, }, { Query: "SELECT is_merging, source, target, unmerged_tables FROM DOLT_MERGE_STATUS;", @@ -2738,7 +2738,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SetUpScript: verifyConstraintsSetupScript, Assertions: []queries.ScriptTestAssertion{ { - Query: "SELECT CONSTRAINTS_VERIFY('child1')", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('child1')", Expected: []sql.Row{{0}}, }, { @@ -2746,7 +2746,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ Expected: []sql.Row{}, }, { - Query: "SELECT CONSTRAINTS_VERIFY('--all', 'child1');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('--all', 'child1');", Expected: []sql.Row{{0}}, }, { @@ -2786,7 +2786,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY();", + Query: "CALL DOLT_VERIFY_CONSTRAINTS();", Expected: []sql.Row{{1}}, }, { @@ -2822,7 +2822,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY('child3');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('child3');", Expected: []sql.Row{{1}}, }, { @@ -2858,7 +2858,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY('child3', 'child4');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('child3', 'child4');", Expected: []sql.Row{{1}}, }, { @@ -2876,7 +2876,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY('child3', 'child4');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('child3', 'child4');", Expected: []sql.Row{{1}}, }, { @@ -2894,7 +2894,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY('--all');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('--all');", Expected: []sql.Row{{1}}, }, { @@ -2930,7 +2930,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY('--all', 'child3');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('--all', 'child3');", Expected: []sql.Row{{1}}, }, { @@ -2966,7 +2966,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SkipResultsCheck: true, }, { - Query: "SELECT CONSTRAINTS_VERIFY('--all', 'child3', 'child4');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('--all', 'child3', 'child4');", Expected: []sql.Row{{1}}, }, { @@ -2998,7 +2998,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SetUpScript: verifyConstraintsSetupScript, Assertions: []queries.ScriptTestAssertion{ { - Query: "SELECT CONSTRAINTS_VERIFY('--output-only', 'child3', 'child4');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('--output-only', 'child3', 'child4');", Expected: []sql.Row{{1}}, }, { @@ -3026,7 +3026,7 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{ SetUpScript: verifyConstraintsSetupScript, Assertions: []queries.ScriptTestAssertion{ { - Query: "SELECT CONSTRAINTS_VERIFY('--all', '--output-only', 'child3', 'child4');", + Query: "CALL DOLT_VERIFY_CONSTRAINTS('--all', '--output-only', 'child3', 'child4');", Expected: []sql.Row{{1}}, }, { diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go index 7226f22e6e..f8e3b477e2 100755 --- a/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_transaction_queries.go @@ -763,7 +763,7 @@ var DoltConflictHandlingTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'initial table');", + "CALL DOLT_COMMIT('-a', '-m', 'initial table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -814,7 +814,7 @@ var DoltConflictHandlingTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'initial table');", + "CALL DOLT_COMMIT('-a', '-m', 'initial table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -865,7 +865,7 @@ var DoltConflictHandlingTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'initial table');", + "CALL DOLT_COMMIT('-a', '-m', 'initial table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -916,7 +916,7 @@ var DoltConflictHandlingTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'initial table');", + "CALL DOLT_COMMIT('-a', '-m', 'initial table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1007,7 +1007,7 @@ var DoltConflictHandlingTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'initial table');", + "CALL DOLT_COMMIT('-a', '-m', 'initial table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1096,7 +1096,7 @@ var DoltConflictHandlingTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'initial table');", + "CALL DOLT_COMMIT('-a', '-m', 'initial table');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1350,14 +1350,14 @@ var DoltSqlFuncTransactionTests = []queries.TransactionTest{ "CREATE TABLE test (pk int primary key, val int)", "CALL DOLT_ADD('.')", "INSERT INTO test VALUES (0, 0)", - "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');", - "SELECT DOLT_CHECKOUT('-b', 'feature-branch')", + "CALL DOLT_COMMIT('-a', '-m', 'Step 1');", + "CALL DOLT_CHECKOUT('-b', 'feature-branch')", "INSERT INTO test VALUES (1, 1);", "UPDATE test SET val=1000 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit');", - "SELECT DOLT_CHECKOUT('main');", + "CALL DOLT_COMMIT('-a', '-m', 'this is a normal commit');", + "CALL DOLT_CHECKOUT('main');", "UPDATE test SET val=1001 WHERE pk=0;", - "SELECT DOLT_COMMIT('-a', '-m', 'update a value');", + "CALL DOLT_COMMIT('-a', '-m', 'update a value');", }, Assertions: []queries.ScriptTestAssertion{ { @@ -1369,8 +1369,8 @@ var DoltSqlFuncTransactionTests = []queries.TransactionTest{ Expected: []sql.Row{}, }, { - Query: "/* client a */ SELECT DOLT_MERGE('feature-branch')", - Expected: []sql.Row{{1}}, + Query: "/* client a */ CALL DOLT_MERGE('feature-branch')", + Expected: []sql.Row{{0, 1}}, }, { Query: "/* client a */ SELECT count(*) from dolt_conflicts_test", @@ -1401,8 +1401,8 @@ var DoltSqlFuncTransactionTests = []queries.TransactionTest{ Expected: []sql.Row{}, }, { - Query: "/* client a */ SELECT DOLT_MERGE('--abort')", - Expected: []sql.Row{{0}}, + Query: "/* client a */ CALL DOLT_MERGE('--abort')", + Expected: []sql.Row{{0, 0}}, }, { Query: "/* client a */ commit", @@ -1417,7 +1417,7 @@ var DoltSqlFuncTransactionTests = []queries.TransactionTest{ Expected: []sql.Row{{}}, }, { - Query: "/* client a */ SELECT DOLT_MERGE('feature-branch')", + Query: "/* client a */ CALL DOLT_MERGE('feature-branch')", ExpectedErrStr: dsess.ErrUnresolvedConflictsCommit.Error(), }, { // client rolled back on merge with conflicts diff --git a/integration-tests/bats/auto_increment.bats b/integration-tests/bats/auto_increment.bats index 9a7f602de8..5755d3bce5 100644 --- a/integration-tests/bats/auto_increment.bats +++ b/integration-tests/bats/auto_increment.bats @@ -442,14 +442,14 @@ CREATE TABLE t ( CALL DOLT_ADD('.'); INSERT INTO t (c0) VALUES (1), (2); -SELECT DOLT_COMMIT('-a', '-m', 'cm1'); -SELECT DOLT_CHECKOUT('-b', 'test'); +call dolt_commit('-a', '-m', 'cm1'); +call dolt_checkout('-b', 'test'); INSERT INTO t (c0) VALUES (3), (4); -SELECT DOLT_COMMIT('-a', '-m', 'cm2'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'cm2'); +call dolt_checkout('main'); -SELECT DOLT_MERGE('test'); +call dolt_merge('test'); INSERT INTO t VALUES (NULL,5),(6,6),(NULL,7); SQL @@ -474,14 +474,14 @@ CREATE TABLE t ( CALL DOLT_ADD('.'); INSERT INTO t (c0) VALUES (1), (2); -SELECT DOLT_COMMIT('-a', '-m', 'cm1'); -SELECT DOLT_CHECKOUT('-b', 'test'); +call dolt_commit('-a', '-m', 'cm1'); +call dolt_checkout('-b', 'test'); INSERT INTO t (c0) VALUES (3), (4); -SELECT DOLT_COMMIT('-a', '-m', 'cm2'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'cm2'); +call dolt_checkout('main'); -SELECT DOLT_MERGE('test'); +call dolt_merge('test'); INSERT INTO t VALUES (10,10),(NULL,11); SQL @@ -508,14 +508,14 @@ CREATE TABLE t ( CALL DOLT_ADD('.'); INSERT INTO t (c0) VALUES (1), (2); -SELECT DOLT_COMMIT('-a', '-m', 'cm1'); -SELECT DOLT_CHECKOUT('-b', 'test'); +call dolt_commit('-a', '-m', 'cm1'); +call dolt_checkout('-b', 'test'); INSERT INTO t VALUES (4,4), (5,5); -SELECT DOLT_COMMIT('-a', '-m', 'cm2'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'cm2'); +call dolt_checkout('main'); -SELECT DOLT_MERGE('test'); +call dolt_merge('test'); INSERT INTO t VALUES (3,3),(NULL,6); SQL @@ -542,14 +542,14 @@ CREATE TABLE t ( CALL DOLT_ADD('.'); INSERT INTO t VALUES (4, 4), (5, 5); -SELECT DOLT_COMMIT('-a', '-m', 'cm1'); -SELECT DOLT_CHECKOUT('-b', 'test'); +call dolt_commit('-a', '-m', 'cm1'); +call dolt_checkout('-b', 'test'); INSERT INTO t VALUES (1,1), (2, 2); -SELECT DOLT_COMMIT('-a', '-m', 'cm2'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'cm2'); +call dolt_checkout('main'); -SELECT DOLT_MERGE('test'); +call dolt_merge('test'); INSERT INTO t VALUES (NULL,6); SQL diff --git a/integration-tests/bats/checkout.bats b/integration-tests/bats/checkout.bats index eb43b39582..6550bd3308 100755 --- a/integration-tests/bats/checkout.bats +++ b/integration-tests/bats/checkout.bats @@ -65,7 +65,7 @@ SQL dolt branch feature dolt sql <')" + dolt sql -q "call dolt_revert('HEAD', '--author', 'john doe ')" run dolt sql -q "SELECT * FROM test" -r=csv [ "$status" -eq "0" ] [[ "$output" =~ "pk,v1" ]] || false @@ -345,7 +345,7 @@ SQL } @test "revert: SQL HEAD & HEAD~1 with author" { - dolt sql -q "SELECT DOLT_REVERT('HEAD', 'HEAD~1', '--author', 'john doe ')" + dolt sql -q "call dolt_revert('HEAD', 'HEAD~1', '--author', 'john doe ')" run dolt sql -q "SELECT * FROM test" -r=csv [ "$status" -eq "0" ] [[ "$output" =~ "pk,v1" ]] || false diff --git a/integration-tests/bats/sql-add.bats b/integration-tests/bats/sql-add.bats index efb90feb0c..d60a5137f8 100644 --- a/integration-tests/bats/sql-add.bats +++ b/integration-tests/bats/sql-add.bats @@ -21,8 +21,8 @@ teardown() { } @test "sql-add: DOLT_ADD all flag works" { - run dolt sql -q "SELECT DOLT_ADD('-A')" - run dolt sql -q "SELECT DOLT_COMMIT('-m', 'Commit1')" + run dolt sql -q "call dolt_add('-A')" + run dolt sql -q "call dolt_commit('-m', 'Commit1')" # Check that everything was added run dolt diff @@ -69,8 +69,8 @@ teardown() { } @test "sql-add: DOLT_ADD all w/ . works" { - run dolt sql -q "SELECT DOLT_ADD('.')" - run dolt sql -q "SELECT DOLT_COMMIT('-m', 'Commit1')" + run dolt sql -q "call dolt_add('.')" + run dolt sql -q "call dolt_commit('-m', 'Commit1')" # Check that everything was added run dolt diff @@ -101,8 +101,8 @@ teardown() { } @test "sql-add: DOLT_ADD all w/ . combined with DOLT_COMMIT -a works" { - run dolt sql -q "SELECT DOLT_ADD('.')" - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1')" + run dolt sql -q "call dolt_add('.')" + run dolt sql -q "call dolt_commit('-a', '-m', 'Commit1')" # Check that everything was added run dolt diff @@ -131,8 +131,8 @@ teardown() { } @test "sql-add: DOLT_ADD can take in one table" { - dolt sql -q "SELECT DOLT_ADD('test')" - dolt sql -q "SELECT DOLT_COMMIT('-m', 'Commit1')" + dolt sql -q "call dolt_add('test')" + dolt sql -q "call dolt_commit('-m', 'Commit1')" # Check that just test was added and not test2. run dolt status @@ -165,8 +165,8 @@ teardown() { } @test "sql-add: DOLT_ADD can take in multiple tables" { - run dolt sql -q "SELECT DOLT_ADD('test', 'test2')" - run dolt sql -q "SELECT DOLT_COMMIT('-m', 'Commit1')" + run dolt sql -q "call dolt_add('test', 'test2')" + run dolt sql -q "call dolt_commit('-m', 'Commit1')" # Check that both test and test2 are added. run dolt diff @@ -203,7 +203,7 @@ teardown() { run ls [[ "$output" =~ "README.md" ]] || false - run dolt sql -q "SELECT DOLT_ADD('README.md')" + run dolt sql -q "call dolt_add('README.md')" [ "$status" -eq 0 ] # Check that the README was added as a new doc. diff --git a/integration-tests/bats/sql-backup.bats b/integration-tests/bats/sql-backup.bats index 57afe6a444..d333e7e57d 100644 --- a/integration-tests/bats/sql-backup.bats +++ b/integration-tests/bats/sql-backup.bats @@ -10,61 +10,61 @@ teardown() { } @test "sql-backup: dolt_backup no argument" { - run dolt sql -q "select dolt_backup()" + run dolt sql -q "call dolt_backup()" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup()" [ "$status" -ne 0 ] } @test "sql-backup: dolt_backup add" { - run dolt sql -q "select dolt_backup('add', 'hostedapidb-0', 'file:///some_directory')" + run dolt sql -q "call dolt_backup('add', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('add', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] } @test "sql-backup: dolt_backup rm" { - run dolt sql -q "select dolt_backup('rm', 'hostedapidb-0')" + run dolt sql -q "call dolt_backup('rm', 'hostedapidb-0')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('rm', 'hostedapidb-0')" [ "$status" -ne 0 ] - run dolt sql -q "select dolt_backup('remove', 'hostedapidb-0')" + run dolt sql -q "call dolt_backup('remove', 'hostedapidb-0')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('remove', 'hostedapidb-0')" [ "$status" -ne 0 ] } @test "sql-backup: dolt_backup restore" { - run dolt sql -q "select dolt_backup('restore', 'hostedapidb-0', 'file:///some_directory')" + run dolt sql -q "call dolt_backup('restore', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('restore', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] - run dolt sql -q "select dolt_backup('restore', 'hostedapidb-0', 'file:///some_directory')" + run dolt sql -q "call dolt_backup('restore', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('restore', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] } @test "sql-backup: dolt_backup unrecognized" { - run dolt sql -q "select dolt_backup('unregonized', 'hostedapidb-0', 'file:///some_directory')" + run dolt sql -q "call dolt_backup('unregonized', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('unrecognized', 'hostedapidb-0', 'file:///some_directory')" [ "$status" -ne 0 ] } @test "sql-backup: dolt_backup sync wrong number of args" { - run dolt sql -q "select dolt_backup('sync')" + run dolt sql -q "call dolt_backup('sync')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('sync')" [ "$status" -ne 0 ] - run dolt sql -q "select dolt_backup('sync', 'hostedapidb-0', 'too many')" + run dolt sql -q "call dolt_backup('sync', 'hostedapidb-0', 'too many')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('sync', 'hostedapidb-0', 'too many')" [ "$status" -ne 0 ] } @test "sql-backup: dolt_backup no such backup" { - run dolt sql -q "select dolt_backup('sync', 'hostedapidb-0')" + run dolt sql -q "call dolt_backup('sync', 'hostedapidb-0')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('sync', 'hostedapidb-0')" [ "$status" -ne 0 ] @@ -74,12 +74,12 @@ teardown() { mkdir the_backup dolt backup add hostedapidb-0 file://./the_backup dolt backup -v - dolt sql -q "select dolt_backup('sync', 'hostedapidb-0')" + dolt sql -q "call dolt_backup('sync', 'hostedapidb-0')" # Initial backup works. dolt backup restore file://./the_backup the_restore (cd the_restore && dolt status) # Backup with nothing to push works. - dolt sql -q "select dolt_backup('sync', 'hostedapidb-0')" + dolt sql -q "call dolt_backup('sync', 'hostedapidb-0')" rm -rf the_backup the_restore @@ -92,7 +92,7 @@ teardown() { @test "sql-backup: dolt_backup sync-url" { mkdir the_backup - dolt sql -q "select dolt_backup('sync-url', 'file://./the_backup')" + dolt sql -q "call dolt_backup('sync-url', 'file://./the_backup')" # Initial backup works. dolt backup restore file://./the_backup the_restore (cd the_restore && dolt status) @@ -106,7 +106,7 @@ teardown() { } @test "sql-backup: dolt_backup sync-url fails for http remotes" { - run dolt sql -q "select dolt_backup('sync-url', 'http://dolthub.com/dolthub/backup')" + run dolt sql -q "call dolt_backup('sync-url', 'http://dolthub.com/dolthub/backup')" [ "$status" -ne 0 ] run dolt sql -q "CALL dolt_backup('sync-url', 'https://dolthub.com/dolthub/backup')" [ "$status" -ne 0 ] diff --git a/integration-tests/bats/sql-batch.bats b/integration-tests/bats/sql-batch.bats index 811befb4e6..c76c51af7b 100644 --- a/integration-tests/bats/sql-batch.bats +++ b/integration-tests/bats/sql-batch.bats @@ -118,7 +118,7 @@ SQL [[ "$output" =~ "test" ]] || false dolt sql -b < 3; SQL [ $status -eq 0 ] @@ -162,12 +162,12 @@ SQL [[ "$output" =~ "main" ]] || false # branch copying from is empty - run dolt sql -q "SELECT DOLT_BRANCH('-c','','copy')" + run dolt sql -q "call dolt_branch('-c','','copy')" [ $status -eq 1 ] [[ "$output" =~ "error: cannot branch empty string" ]] || false # branch copying to is empty - run dolt sql -q "SELECT DOLT_BRANCH('-c','main','')" + run dolt sql -q "call dolt_branch('-c','main','')" [ $status -eq 1 ] [[ "$output" =~ "error: cannot branch empty string" ]] || false @@ -178,12 +178,12 @@ SQL [[ ! "$output" =~ "original" ]] || false # branch copying from that don't exist - run dolt sql -q "SELECT DOLT_BRANCH('-c', 'original', 'copy');" + run dolt sql -q "call dolt_branch('-c', 'original', 'copy');" [ $status -eq 1 ] [[ "$output" =~ "fatal: A branch named 'original' not found" ]] || false # branch copying to that exists - run dolt sql -q "SELECT DOLT_BRANCH('-c', 'main', 'existing_branch');" + run dolt sql -q "call dolt_branch('-c', 'main', 'existing_branch');" [ $status -eq 1 ] [[ "$output" =~ "fatal: A branch named 'existing_branch' already exists." ]] || false } @@ -226,7 +226,7 @@ SQL [ $status -eq 0 ] mainhash=$output - dolt sql -q "SELECT DOLT_BRANCH('feature-branch');" + dolt sql -q "call dolt_branch('feature-branch');" run dolt sql -q "SELECT hash FROM dolt_branches WHERE name='feature-branch';" [ $status -eq 0 ] [ "$output" = "$mainhash" ] @@ -245,14 +245,14 @@ SQL [ "$output" = "$mainhash" ] } -@test "sql-branch: SELECT DOLT_BRANCH to rename and delete" { +@test "sql-branch: call dolt_branch to rename and delete" { dolt add . && dolt commit -m "1, 2, and 3 in test table" dolt branch new_branch - run dolt sql -q "SELECT DOLT_BRANCH('-m', 'new_branch', 'changed');" + run dolt sql -q "call dolt_branch('-m', 'new_branch', 'changed');" [ $status -eq 0 ] - run dolt sql -q "SELECT DOLT_BRANCH('-d', 'changed');" + run dolt sql -q "call dolt_branch('-d', 'changed');" [ $status -eq 0 ] dolt branch branch_with_unpushed_commit @@ -260,11 +260,11 @@ SQL dolt commit --allow-empty -am 'empty commit' dolt checkout main - run dolt sql -q "SELECT DOLT_BRANCH('-d', 'branch_with_unpushed_commit');" + run dolt sql -q "call dolt_branch('-d', 'branch_with_unpushed_commit');" [ $status -eq 1 ] [[ "$output" =~ "attempted to delete a branch that is not fully merged" ]] || false - run dolt sql -q "SELECT DOLT_BRANCH('-D', 'branch_with_unpushed_commit');" + run dolt sql -q "call dolt_branch('-D', 'branch_with_unpushed_commit');" [ $status -eq 0 ] } diff --git a/integration-tests/bats/sql-checkout.bats b/integration-tests/bats/sql-checkout.bats index 3e7042338c..4e12d7a586 100644 --- a/integration-tests/bats/sql-checkout.bats +++ b/integration-tests/bats/sql-checkout.bats @@ -19,10 +19,10 @@ teardown() { } @test "sql-checkout: DOLT_CHECKOUT just works" { - run dolt sql -q "SELECT DOLT_CHECKOUT('-b', 'feature-branch')" + run dolt sql -q "call dolt_checkout('-b', 'feature-branch')" [ $status -eq 0 ] - # dolt sql -q "select dolt_checkout() should not change the branch + # dolt sql -q "call dolt_checkout() should not change the branch # It changes the branch for that session which ends after the SQL # statements are executed. run dolt status @@ -33,7 +33,7 @@ teardown() { [ $status -eq 0 ] [[ "$output" =~ "feature-branch" ]] || false - run dolt sql -q "SELECT DOLT_CHECKOUT('main');" + run dolt sql -q "call dolt_checkout('main');" [ $status -eq 0 ] run dolt status @@ -45,7 +45,7 @@ teardown() { run dolt sql -q "CALL DOLT_CHECKOUT('-b', 'feature-branch')" [ $status -eq 0 ] - # dolt sql -q "select dolt_checkout() should not change the branch + # dolt sql -q "call dolt_checkout() should not change the branch # It changes the branch for that session which ends after the SQL # statements are executed. run dolt status @@ -74,7 +74,7 @@ SQL run dolt sql -q "CALL DCHECKOUT('-b', 'feature-branch')" [ $status -eq 0 ] - # dolt sql -q "select dolt_checkout() should not change the branch + # dolt sql -q "call dolt_checkout() should not change the branch # It changes the branch for that session which ends after the SQL # statements are executed. run dolt status @@ -100,17 +100,17 @@ SQL } @test "sql-checkout: DOLT_CHECKOUT -b throws error on branches that already exist" { - run dolt sql -q "SELECT DOLT_CHECKOUT('-b', 'main')" + run dolt sql -q "call dolt_checkout('-b', 'main')" [ $status -eq 1 ] } @test "sql-checkout: CALL DOLT_CHECKOUT -b throws error on branches that already exist" { - run dolt sql -q "CALL SELECT DOLT_CHECKOUT('-b', 'main')" + run dolt sql -q "CALL call dolt_checkout('-b', 'main')" [ $status -eq 1 ] } @test "sql-checkout: DOLT_CHECKOUT throws error on branches that don't exist" { - run dolt sql -q "SELECT DOLT_CHECKOUT('feature-branch')" + run dolt sql -q "call dolt_checkout('feature-branch')" [ $status -eq 1 ] } @@ -120,7 +120,7 @@ SQL } @test "sql-checkout: DOLT_CHECKOUT -b throws error on empty branch" { - run dolt sql -q "SELECT DOLT_CHECKOUT('-b', '')" + run dolt sql -q "call dolt_checkout('-b', '')" [ $status -eq 1 ] } @@ -131,7 +131,7 @@ SQL @test "sql-checkout: DOLT_CHECKOUT updates the head ref session var" { run dolt sql < 3; SQL [ $status -eq 0 ] @@ -184,7 +184,7 @@ SQL [[ "$output" =~ "4" ]] || false run dolt sql << SQL -SELECT DOLT_CHECKOUT('-b', 'feature-branch2'); +call dolt_checkout('-b', 'feature-branch2'); insert into test values (5); select * from test where pk > 3; SQL @@ -205,7 +205,7 @@ SQL # In a new session, the value inserted should still be there run dolt sql << SQL -SELECT DOLT_CHECKOUT('feature-branch2'); +call dolt_checkout('feature-branch2'); select * from test where pk > 3; SQL [ $status -eq 0 ] @@ -213,7 +213,7 @@ SQL [[ "$output" =~ "5" ]] || false # This is an error on the command line, but not in SQL - run dolt sql -q "SELECT DOLT_CHECKOUT('main')" + run dolt sql -q "call dolt_checkout('main')" [ $status -eq 0 ] } @@ -281,7 +281,7 @@ SQL [[ "$output" =~ "5" ]] || false # This is an error on the command line, but not in SQL - run dolt sql -q "SELECT DOLT_CHECKOUT('main')" + run dolt sql -q "call dolt_checkout('main')" [ $status -eq 0 ] } @@ -293,14 +293,14 @@ SQL emptydiff=$output run dolt sql << SQL -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_checkout('-b', 'feature-branch'); SELECT * FROM dolt_diff_test; SQL [ $status -eq 0 ] [[ "$output" =~ "$emptydiff" ]] || false run dolt sql << SQL -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_checkout('feature-branch'); SELECT * FROM dolt_diff_test; SQL [ $status -eq 0 ] @@ -313,14 +313,14 @@ SQL [[ ! "$output" =~ "$emptydiff" ]] || false run dolt sql << SQL -SELECT DOLT_CHECKOUT('-b', 'feature-branch2'); +call dolt_checkout('-b', 'feature-branch2'); SELECT * FROM dolt_diff_test; SQL [ $status -eq 0 ] [[ "$output" =~ "$emptydiff" ]] || false run dolt sql << SQL -SELECT DOLT_CHECKOUT('feature-branch2'); +call dolt_checkout('feature-branch2'); SELECT * FROM dolt_diff_test; SQL [ $status -eq 0 ] @@ -375,10 +375,10 @@ SQL dolt add . && dolt commit -m "0, 1, and 2 in test table" run dolt sql << SQL -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (4); -SELECT DOLT_ADD('.'); -SELECT DOLT_COMMIT('-m', 'Added 4', '--author', 'John Doe '); +call dolt_add('.'); +call dolt_commit('-m', 'Added 4', '--author', 'John Doe '); SQL [ $status -eq 0 ] @@ -441,7 +441,7 @@ SQL dolt add . && dolt commit -m "0, 1, and 2 in test table" run dolt sql << SQL -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (4); select * from test where pk > 3; SQL @@ -450,8 +450,8 @@ SQL [[ "$output" =~ "4" ]] || false run dolt sql << SQL -SELECT DOLT_CHECKOUT('feature-branch'); -SELECT DOLT_CHECKOUT('test'); +call dolt_checkout('feature-branch'); +call dolt_checkout('test'); select * from test where pk > 3; SQL @@ -489,15 +489,15 @@ CREATE TABLE one_pk ( c2 BIGINT, PRIMARY KEY (pk1) ); -SELECT DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_add('.'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -select dolt_commit('-a', '-m', "changed feature-branch"); +call dolt_commit('-a', '-m', "changed feature-branch"); SQL [ $status -eq 0 ] @@ -523,7 +523,7 @@ CREATE TABLE one_pk ( c2 BIGINT, PRIMARY KEY (pk1) ); -SELECT DOLT_ADD('.'); +call dolt_add('.'); CALL DOLT_COMMIT('-a', '-m', 'add tables'); CALL DOLT_CHECKOUT('-b', 'feature-branch'); CALL DOLT_CHECKOUT('main'); @@ -550,7 +550,7 @@ SQL } @test "sql-checkout: DOLT_CHECKOUT does not throw an error when checking out to the same branch" { - run dolt sql -q "SELECT DOLT_CHECKOUT('main')" + run dolt sql -q "call dolt_checkout('main')" [ $status -eq 0 ] [[ "$output" =~ "0" ]] || false } diff --git a/integration-tests/bats/sql-commit.bats b/integration-tests/bats/sql-commit.bats index 3d42fc6aa5..80503fd257 100644 --- a/integration-tests/bats/sql-commit.bats +++ b/integration-tests/bats/sql-commit.bats @@ -20,10 +20,10 @@ teardown() { } @test "sql-commit: DOLT_COMMIT without a message throws error" { - run dolt sql -q "SELECT DOLT_ADD('.')" + run dolt sql -q "call dolt_add('.')" [ $status -eq 0 ] - run dolt sql -q "SELECT DOLT_COMMIT()" + run dolt sql -q "call dolt_commit()" [ $status -eq 1 ] run dolt log [ $status -eq 0 ] @@ -56,10 +56,10 @@ teardown() { } @test "sql-commit: DOLT_COMMIT with just a message reads session parameters" { - run dolt sql -q "SELECT DOLT_ADD('.')" + run dolt sql -q "call dolt_add('.')" [ $status -eq 0 ] - run dolt sql -q "SELECT DOLT_COMMIT('-m', 'Commit1')" + run dolt sql -q "call dolt_commit('-m', 'Commit1')" [ $status -eq 0 ] run dolt log [ $status -eq 0 ] @@ -82,7 +82,7 @@ teardown() { } @test "sql-commit: DOLT_COMMIT with the all flag performs properly" { - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1')" + run dolt sql -q "call dolt_commit('-a', '-m', 'Commit1')" # Check that everything was added run dolt diff @@ -112,9 +112,9 @@ teardown() { } @test "sql-commit: DOLT_COMMIT with all flag, message and author" { - run dolt sql -r csv -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1', '--author', 'John Doe ') as commit_hash" + run dolt sql -r csv -q "call dolt_commit('-a', '-m', 'Commit1', '--author', 'John Doe ')" [ $status -eq 0 ] - DCOMMIT=$output + DCOMMIT=$(echo "$output" | grep -E -o '[a-zA-Z0-9_]{32}') # Check that everything was added run dolt diff @@ -141,11 +141,11 @@ teardown() { dolt config --global --unset user.name dolt config --global --unset user.email - run dolt sql -q "SELECT DOLT_ADD('.')" + run dolt sql -q "call dolt_add('.')" - run dolt sql -q "SELECT DOLT_COMMIT('-m', 'Commit1', '--author', 'John Doe ') as commit_hash" + run dolt sql -q "call dolt_commit('-m', 'Commit1', '--author', 'John Doe ')" [ "$status" -eq 0 ] - DCOMMIT=$output + DCOMMIT=$(echo "$output" | grep -E -o '[a-zA-Z0-9_]{32}') run dolt log [ "$status" -eq 0 ] @@ -169,7 +169,7 @@ teardown() { @test "sql-commit: DOLT_COMMIT immediately updates dolt log system table." { run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Commit1'); +call dolt_commit('-a', '-m', 'Commit1'); SELECT * FROM dolt_log; SQL @@ -190,7 +190,7 @@ SQL @test "sql-commit: DOLT_COMMIT immediately updates dolt diff system table." { original_hash=$(get_head_commit) run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Commit1'); +call dolt_commit('-a', '-m', 'Commit1'); SELECT from_commit FROM dolt_diff_test WHERE to_commit = hashof('head'); SQL @@ -215,7 +215,7 @@ SQL head_variable=@@dolt_repo_$$_head head_commit=$(get_head_commit) run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Commit1'); +call dolt_commit('-a', '-m', 'Commit1'); SELECT $head_variable = HASHOF('head'); SELECT $head_variable SQL @@ -258,8 +258,8 @@ SQL CREATE TABLE test2 ( pk int primary key ); -SELECT DOLT_ADD('test'); -SELECT DOLT_COMMIT('-m', '0, 1, 2 in test'); +call dolt_add('test'); +call dolt_commit('-m', '0, 1, 2 in test'); SELECT $head_variable = HASHOF('head'); SQL @@ -284,9 +284,9 @@ SQL # Now another partial commit run dolt sql << SQL -SELECT DOLT_ADD('test2'); +call dolt_add('test2'); insert into test values (20); -SELECT DOLT_COMMIT('-m', 'added test2 table'); +call dolt_commit('-m', 'added test2 table'); SELECT $head_variable = HASHOF('head'); SQL @@ -390,7 +390,7 @@ CREATE TABLE objects ( INSERT INTO objects (id,name,color) VALUES (1,'truck','red'),(2,'ball','green'),(3,'shoe','blue'); -SELECT DOLT_COMMIT('-fam', 'Commit1'); +call dolt_commit('-fam', 'Commit1'); SQL [ $status -eq 0 ] @@ -440,7 +440,7 @@ SQL } @test "sql-commit: missing message does not panic and throws an error" { - run dolt sql -q "SELECT DOLT_COMMIT('--allow-empty', '-fam')" + run dolt sql -q "call dolt_commit('--allow-empty', '-fam')" [ $status -eq 1 ] ! [[ "$output" =~ 'panic' ]] || false [[ "$output" =~ 'error: no value for option `message' ]] || false diff --git a/integration-tests/bats/sql-create-database.bats b/integration-tests/bats/sql-create-database.bats index 6217e288c8..240ecfd94f 100644 --- a/integration-tests/bats/sql-create-database.bats +++ b/integration-tests/bats/sql-create-database.bats @@ -81,7 +81,7 @@ create database mydb; use mydb; create table test(a int primary key); call dolt_add('.'); -select dolt_commit("-am", "first commit"); +call dolt_commit("-am", "first commit"); SQL [ -d mydb ] @@ -109,12 +109,12 @@ create database mydb2; use mydb1; create table test(a int primary key); call dolt_add('.'); -select dolt_commit("-am", "first commit mydb1"); +call dolt_commit("-am", "first commit mydb1"); use mydb2; begin; create table test(a int primary key); call dolt_add('.'); -select dolt_commit("-am", "first commit mydb2"); +call dolt_commit("-am", "first commit mydb2"); SQL [ -d db_dir/mydb1 ] @@ -153,12 +153,12 @@ create database mydb2; use mydb1; create table test(a int primary key); call dolt_add('.'); -select dolt_commit("-am", "first commit mydb1"); +call dolt_commit("-am", "first commit mydb1"); use mydb2; begin; create table test(a int primary key); call dolt_add('.'); -select dolt_commit("-am", "first commit mydb2"); +call dolt_commit("-am", "first commit mydb2"); SQL [ -d "$absdir/mydb1" ] diff --git a/integration-tests/bats/sql-fetch.bats b/integration-tests/bats/sql-fetch.bats index 9b3a6c8895..08efa9433b 100644 --- a/integration-tests/bats/sql-fetch.bats +++ b/integration-tests/bats/sql-fetch.bats @@ -39,7 +39,7 @@ teardown() { @test "sql-fetch: dolt_fetch default" { cd repo2 - dolt sql -q "select dolt_fetch()" + dolt sql -q "call dolt_fetch()" run dolt diff main origin/main [ "$status" -eq 0 ] @@ -81,7 +81,7 @@ teardown() { @test "sql-fetch: dolt_fetch origin" { cd repo2 - dolt sql -q "select dolt_fetch('origin')" + dolt sql -q "call dolt_fetch('origin')" run dolt diff main origin/main [ "$status" -eq 0 ] @@ -109,7 +109,7 @@ teardown() { @test "sql-fetch: dolt_fetch main" { cd repo2 - dolt sql -q "select dolt_fetch('origin', 'main')" + dolt sql -q "call dolt_fetch('origin', 'main')" run dolt diff main origin/main [ "$status" -eq 0 ] @@ -137,7 +137,7 @@ teardown() { @test "sql-fetch: dolt_fetch custom remote" { cd repo2 - dolt sql -q "select dolt_fetch('test-remote')" + dolt sql -q "call dolt_fetch('test-remote')" run dolt diff main test-remote/main [ "$status" -eq 0 ] @@ -165,7 +165,7 @@ teardown() { @test "sql-fetch: dolt_fetch specific ref" { cd repo2 - dolt sql -q "select dolt_fetch('test-remote', 'refs/heads/main:refs/remotes/test-remote/main')" + dolt sql -q "call dolt_fetch('test-remote', 'refs/heads/main:refs/remotes/test-remote/main')" run dolt diff main test-remote/main [ "$status" -eq 0 ] @@ -196,7 +196,7 @@ teardown() { dolt push origin feature cd ../repo2 - dolt sql -q "select dolt_fetch('origin', 'feature')" + dolt sql -q "call dolt_fetch('origin', 'feature')" run dolt diff main origin/feature [ "$status" -eq 0 ] @@ -231,7 +231,7 @@ teardown() { dolt push origin v1 cd ../repo2 - dolt sql -q "select dolt_fetch('origin', 'main')" + dolt sql -q "call dolt_fetch('origin', 'main')" run dolt diff main v1 [ "$status" -eq 0 ] @@ -268,7 +268,7 @@ teardown() { dolt push origin v1 cd ../repo2 - dolt sql -q "select dolt_fetch('origin', 'refs/tags/v1:refs/tags/v1')" + dolt sql -q "call dolt_fetch('origin', 'refs/tags/v1:refs/tags/v1')" run dolt diff main origin/v1 [ "$status" -eq 0 ] @@ -301,7 +301,7 @@ teardown() { @test "sql-fetch: dolt_fetch rename ref" { cd repo2 - dolt sql -q "select dolt_fetch('test-remote', 'refs/heads/main:refs/remotes/test-remote/other')" + dolt sql -q "call dolt_fetch('test-remote', 'refs/heads/main:refs/remotes/test-remote/other')" run dolt diff main test-remote/other [ "$status" -eq 0 ] @@ -330,7 +330,7 @@ teardown() { @test "sql-fetch: dolt_fetch override local branch" { skip "todo more flexible refspec support" cd repo2 - dolt sql -q "select dolt_fetch('origin', 'main:refs/heads/main')" + dolt sql -q "call dolt_fetch('origin', 'main:refs/heads/main')" dolt diff main origin/main [ "$status" -eq 0 ] @@ -366,11 +366,11 @@ teardown() { dolt push --force origin main cd ../repo1 - run dolt sql -q "select dolt_fetch('origin', 'main')" + run dolt sql -q "call dolt_fetch('origin', 'main')" [ "$status" -eq 1 ] [[ "$output" =~ "fetch failed: can't fast forward merge" ]] || false - dolt sql -q "select dolt_fetch('--force', 'origin', 'main')" + dolt sql -q "call dolt_fetch('--force', 'origin', 'main')" dolt diff main origin/main run dolt diff main origin/main @@ -411,7 +411,7 @@ teardown() { @test "sql-fetch: dolt_fetch unknown remote fails" { cd repo2 dolt remote remove origin - run dolt sql -q "select dolt_fetch('unknown')" + run dolt sql -q "call dolt_fetch('unknown')" [ "$status" -eq 1 ] [[ "$output" =~ "unknown remote" ]] || false } @@ -427,7 +427,7 @@ teardown() { @test "sql-fetch: dolt_fetch unknown remote with fetchspec fails" { cd repo2 dolt remote remove origin - run dolt sql -q "select dolt_fetch('unknown', 'main')" + run dolt sql -q "call dolt_fetch('unknown', 'main')" [ "$status" -eq 1 ] [[ "$output" =~ "unknown remote" ]] || false } @@ -442,7 +442,7 @@ teardown() { @test "sql-fetch: dolt_fetch unknown ref fails" { cd repo2 - run dolt sql -q "select dolt_fetch('origin', 'unknown')" + run dolt sql -q "call dolt_fetch('origin', 'unknown')" [ "$status" -eq 1 ] [[ "$output" =~ "invalid ref spec: 'unknown'" ]] || false } @@ -457,7 +457,7 @@ teardown() { @test "sql-fetch: dolt_fetch empty remote fails" { cd repo2 dolt remote remove origin - run dolt sql -q "select dolt_fetch('')" + run dolt sql -q "call dolt_fetch('')" [ "$status" -eq 1 ] [[ "$output" =~ "unknown remote" ]] || false } @@ -472,7 +472,7 @@ teardown() { @test "sql-fetch: dolt_fetch empty ref fails" { cd repo2 - run dolt sql -q "select dolt_fetch('origin', '')" + run dolt sql -q "call dolt_fetch('origin', '')" [ "$status" -eq 1 ] [[ "$output" =~ "invalid fetch spec: ''" ]] || false } diff --git a/integration-tests/bats/sql-merge.bats b/integration-tests/bats/sql-merge.bats index ff94c3d6df..5a2e60120e 100644 --- a/integration-tests/bats/sql-merge.bats +++ b/integration-tests/bats/sql-merge.bats @@ -20,9 +20,9 @@ teardown() { } @test "sql-merge: DOLT_MERGE with unknown branch name throws an error" { - dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Step 1');" + dolt sql -q "call dolt_commit('-a', '-m', 'Step 1');" - run dolt sql -q "SELECT DOLT_MERGE('feature-branch');" + run dolt sql -q "call dolt_merge('feature-branch');" log_status_eq 1 } @@ -35,14 +35,14 @@ teardown() { @test "sql-merge: DOLT_MERGE works with ff" { dolt sql < 0 FROM test WHERE pk=3; SQL log_status_eq 0 @@ -199,13 +199,13 @@ SQL @test "sql-merge: DOLT_MERGE with autocommit off works in fast-forward." { dolt sql << SQL set autocommit = off; -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'this is a ff'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); -SELECT DOLT_CHECKOUT('-b', 'new-branch'); +call dolt_commit('-a', '-m', 'this is a ff'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); +call dolt_checkout('-b', 'new-branch'); SQL run dolt sql -r csv -q "select * from test order by pk" @@ -225,7 +225,7 @@ INSERT INTO test VALUES (3); CALL DOLT_COMMIT('-a', '-m', 'this is a ff'); CALL DOLT_CHECKOUT('main'); CALL DOLT_MERGE('feature-branch'); -SELECT DOLT_CHECKOUT('-b', 'new-branch'); +call dolt_checkout('-b', 'new-branch'); SQL run dolt sql -r csv -q "select * from test order by pk" @@ -239,12 +239,12 @@ SQL @test "sql-merge: DOLT_MERGE no-ff works with autocommit off." { dolt sql << SQL set autocommit = off; -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'this is a ff'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch', '-no-ff'); +call dolt_commit('-a', '-m', 'this is a ff'); +call dolt_checkout('main'); +call dolt_merge('feature-branch', '-no-ff'); COMMIT; SQL @@ -282,17 +282,17 @@ CREATE TABLE test2 (pk int primary key, val int); INSERT INTO test2 VALUES (0, 0); SET autocommit = 0; CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test2 VALUES (1, 1); UPDATE test2 SET val=1000 WHERE pk=0; -SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'this is a normal commit'); +call dolt_checkout('main'); UPDATE test2 SET val=1001 WHERE pk=0; -SELECT DOLT_COMMIT('-a', '-m', 'update a value'); -SELECT DOLT_MERGE('feature-branch', '-m', 'this is a merge'); +call dolt_commit('-a', '-m', 'update a value'); +call dolt_merge('feature-branch', '-m', 'this is a merge'); DELETE FROM dolt_conflicts_test2; -SELECT DOLT_COMMIT('-a', '-m', 'remove conflicts'); +call dolt_commit('-a', '-m', 'remove conflicts'); SQL run dolt sql -r csv -q "select * from test2 order by pk" @@ -329,14 +329,14 @@ SQL @test "sql-merge: DOLT_MERGE works with autocommit off." { dolt sql << SQL set autocommit = off; -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'this is a normal commit'); +call dolt_checkout('main'); INSERT INTO test VALUES (5); -SELECT DOLT_COMMIT('-a', '-m', 'this is a normal commit'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'this is a normal commit'); +call dolt_merge('feature-branch'); COMMIT; SQL @@ -374,10 +374,10 @@ SQL @test "sql-merge: DOLT_MERGE correctly returns head and working session variables." { dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'this is a ff'); +call dolt_commit('-a', '-m', 'this is a ff'); SQL head_variable=@@dolt_repo_$$_head @@ -385,8 +385,8 @@ SQL head_hash=$(get_head_commit) dolt sql << SQL -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); SQL run dolt sql -q "SELECT $head_variable" @@ -428,24 +428,23 @@ SQL @test "sql-merge: DOLT_MERGE correctly merges branches with differing content in same table without conflicts" { dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'Insert 3'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'Insert 3'); +call dolt_checkout('main'); INSERT INTO test VALUES (10000); -SELECT DOLT_COMMIT('-a', '-m', 'Insert 10000'); +call dolt_commit('-a', '-m', 'Insert 10000'); SQL run dolt sql << SQL -SELECT DOLT_MERGE('feature-branch', '--no-commit'); +call dolt_merge('feature-branch', '--no-commit'); SELECT COUNT(*) = 2 FROM test WHERE pk > 2; SQL log_status_eq 0 [[ "$output" =~ "true" ]] || false [[ "$output" =~ "true" ]] || false - [[ "${lines[1]}" =~ "DOLT_MERGE('feature-branch', '--no-commit')" ]] || false # validate that merge returns 1 not "Updating..." [[ "${lines[3]}" =~ "0" ]] || false ! [[ "$output" =~ "Updating" ]] || false @@ -471,7 +470,7 @@ SQL [[ "$output" =~ "Changes to be committed:" ]] || false [[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Finish up Merge')"; + run dolt sql -q "call dolt_commit('-a', '-m', 'Finish up Merge')"; log_status_eq 0 run dolt status @@ -524,7 +523,7 @@ SQL [[ "$output" =~ "Changes to be committed:" ]] || false [[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Finish up Merge')"; + run dolt sql -q "call dolt_commit('-a', '-m', 'Finish up Merge')"; log_status_eq 0 run dolt status @@ -538,12 +537,12 @@ SQL @test "sql-merge: DOLT_MERGE works with no-ff" { run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'update feature-branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch', '-no-ff', '-m', 'this is a no-ff'); +call dolt_commit('-a', '-m', 'update feature-branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch', '-no-ff', '-m', 'this is a no-ff'); SELECT COUNT(*) = 4 FROM dolt_log SQL log_status_eq 0 @@ -574,18 +573,18 @@ SQL @test "sql-merge: DOLT_MERGE -no-ff correctly changes head and working session variables." { dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'update feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'update feature-branch'); +call dolt_checkout('main'); SQL head_variable=@@dolt_repo_$$_head head_hash=$(get_head_commit) working_variable=@@dolt_repo_$$_working working_hash=$(get_working_hash) - run dolt sql -q "SELECT DOLT_MERGE('feature-branch', '-no-ff', '-m', 'this is a no-ff');" + run dolt sql -q "call dolt_merge('feature-branch', '-no-ff', '-m', 'this is a no-ff');" log_status_eq 0 run dolt sql -q "SELECT $head_variable" @@ -633,16 +632,16 @@ CREATE TABLE one_pk ( PRIMARY KEY (pk1) ); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); SQL log_status_eq 1 [[ $output =~ "Merge conflict detected, transaction rolled back. Merge conflicts must be resolved using the dolt_conflicts tables before committing a transaction. To commit transactions with merge conflicts, set @@dolt_allow_commit_conflicts = 1" ]] || false @@ -656,7 +655,7 @@ SQL [[ $output =~ "no merge to abort" ]] || false # make sure a clean SQL session doesn't have any merge going - run dolt sql -q "SELECT DOLT_MERGE('--abort');" + run dolt sql -q "call dolt_merge('--abort');" log_status_eq 1 [[ $output =~ "no merge to abort" ]] || false @@ -736,16 +735,16 @@ CREATE TABLE one_pk ( PRIMARY KEY (pk1) ); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); SQL log_status_eq 1 [[ $output =~ "Merge conflict detected, transaction rolled back. Merge conflicts must be resolved using the dolt_conflicts tables before committing a transaction. To commit transactions with merge conflicts, set @@dolt_allow_commit_conflicts = 1" ]] || false @@ -761,24 +760,23 @@ SQL # now merge, examine the conflicts, and abort run dolt sql -r csv << SQL SET autocommit = off; -SELECT DOLT_MERGE('feature-branch'); +call dolt_merge('feature-branch'); SELECT * FROM dolt_conflicts; -SELECT DOLT_MERGE('--abort'); +call dolt_merge('--abort'); SQL log_status_eq 0 [[ "${lines[2]}" =~ "table,num_conflicts" ]] || false [[ "${lines[3]}" =~ "one_pk,1" ]] || false - [[ "${lines[4]}" =~ "DOLT_MERGE('--abort')" ]] || false [[ "${lines[5]}" =~ "0" ]] || false # now resolve commits run dolt sql << SQL SET autocommit = off; -SELECT DOLT_MERGE('feature-branch'); +call dolt_merge('feature-branch'); REPLACE INTO one_pk (pk1, c1, c2) SELECT their_pk1, their_c1, their_c2 FROM dolt_conflicts_one_pk WHERE their_pk1 IS NOT NULL; DELETE FROM one_pk WHERE pk1 in (SELECT base_pk1 FROM dolt_conflicts_one_pk WHERE their_pk1 IS NULL); DELETE FROM dolt_conflicts_one_pk; -SELECT DOLT_COMMIT('-a', '-m', 'Finish Resolving'); +call dolt_commit('-a', '-m', 'Finish Resolving'); SQL log_status_eq 0 @@ -803,17 +801,17 @@ CREATE TABLE one_pk ( PRIMARY KEY (pk1) ); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); -SELECT DOLT_MERGE('--abort'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); +call dolt_merge('--abort'); insert into one_pk values (9,9,9); commit; SQL @@ -884,17 +882,17 @@ CREATE TABLE one_pk ( PRIMARY KEY (pk1) ); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); -SELECT DOLT_MERGE('--abort'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); +call dolt_merge('--abort'); commit; SQL log_status_eq 0 @@ -946,22 +944,22 @@ CREATE TABLE one_pk ( PRIMARY KEY (pk1) ); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); SQL run dolt sql -r csv -q "SELECT count(*) from dolt_conflicts" [[ "$output" =~ "1" ]] || false - run dolt sql -q "SELECT DOLT_MERGE('feature-branch');" + run dolt sql -q "call dolt_merge('feature-branch');" log_status_eq 1 [[ $output =~ "merging is not possible because you have not committed an active merge" ]] || false } @@ -991,22 +989,22 @@ SQL run dolt sql -r csv -q "SELECT count(*) from dolt_conflicts" [[ "$output" =~ "1" ]] || false - run dolt sql -q "SELECT DOLT_MERGE('feature-branch');" + run dolt sql -q "call dolt_merge('feature-branch');" log_status_eq 1 [[ $output =~ "merging is not possible because you have not committed an active merge" ]] || false } @test "sql-merge: DOLT_MERGE during an active merge throws an error" { run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'Insert 3'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'Insert 3'); +call dolt_checkout('main'); INSERT INTO test VALUES (500000); -SELECT DOLT_COMMIT('-a', '-m', 'Insert 500000'); -SELECT DOLT_MERGE('feature-branch', '--no-commit'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'Insert 500000'); +call dolt_merge('feature-branch', '--no-commit'); +call dolt_merge('feature-branch'); SQL log_status_eq 1 @@ -1032,12 +1030,12 @@ SQL @test "sql-merge: DOLT_MERGE works with ff and squash" { run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'this is a ff'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch', '--squash'); +call dolt_commit('-a', '-m', 'this is a ff'); +call dolt_checkout('main'); +call dolt_merge('feature-branch', '--squash'); SELECT COUNT(*) > 0 FROM test WHERE pk=3; SQL log_status_eq 0 @@ -1057,7 +1055,7 @@ SQL [[ "$output" =~ "Changes to be committed:" ]] || false [[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'hi');" + run dolt sql -q "call dolt_commit('-a', '-m', 'hi');" log_status_eq 0 run dolt status @@ -1102,14 +1100,14 @@ SQL @test "sql-merge: DOLT_MERGE with no-ff and squash works." { dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'Insert 3'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'Insert 3'); +call dolt_checkout('main'); INSERT INTO test VALUES (500000); -SELECT DOLT_COMMIT('-a', '-m', 'Insert 500000'); -SELECT DOLT_MERGE('feature-branch', '--squash', '--no-commit'); +call dolt_commit('-a', '-m', 'Insert 500000'); +call dolt_merge('feature-branch', '--squash', '--no-commit'); SQL run dolt status @@ -1118,7 +1116,7 @@ SQL [[ "$output" =~ "Changes to be committed:" ]] || false [[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Finish up Merge')"; + run dolt sql -q "call dolt_commit('-a', '-m', 'Finish up Merge')"; log_status_eq 0 run dolt status @@ -1162,15 +1160,15 @@ SQL @test "sql-merge: DOLT_MERGE throws errors with working set changes." { run dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'this is a ff'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'this is a ff'); +call dolt_checkout('main'); CREATE TABLE tbl ( pk int primary key ); -SELECT DOLT_MERGE('feature-branch'); +call dolt_merge('feature-branch'); SQL log_status_eq 1 [[ "$output" =~ "cannot merge with uncommitted changes" ]] || false @@ -1194,21 +1192,21 @@ SQL @test "sql-merge: DOLT_MERGE with a long series of changing operations works." { dolt sql << SQL -SELECT DOLT_COMMIT('-a', '-m', 'Step 1'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); +call dolt_commit('-a', '-m', 'Step 1'); +call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); INSERT INTO test VALUES (4); INSERT INTO test VALUES (21232); DELETE FROM test WHERE pk=4; UPDATE test SET pk=21 WHERE pk=21232; -SELECT DOLT_COMMIT('-a', '-m', 'Insert 3'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'Insert 3'); +call dolt_checkout('main'); INSERT INTO test VALUES (500000); INSERT INTO test VALUES (500001); DELETE FROM test WHERE pk=500001; UPDATE test SET pk=60 WHERE pk=500000; -SELECT DOLT_COMMIT('-a', '-m', 'Insert 60'); -SELECT DOLT_MERGE('feature-branch', '--no-commit'); +call dolt_commit('-a', '-m', 'Insert 60'); +call dolt_merge('feature-branch', '--no-commit'); SQL run dolt status @@ -1217,7 +1215,7 @@ SQL [[ "$output" =~ "Changes to be committed:" ]] || false [[ "$output" =~ ([[:space:]]*modified:[[:space:]]*test) ]] || false - run dolt sql -q "SELECT DOLT_COMMIT('-a', '-m', 'Finish up Merge')"; + run dolt sql -q "call dolt_commit('-a', '-m', 'Finish up Merge')"; log_status_eq 0 run dolt status @@ -1304,23 +1302,23 @@ CREATE TABLE one_pk ( PRIMARY KEY (pk1) ); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); SHOW WARNINGS; SELECT COUNT(*) FROM dolt_conflicts where num_conflicts > 0; rollback; SQL log_status_eq 0 - [[ "$output" =~ "| DOLT_MERGE('feature-branch') |" ]] || false - [[ "$output" =~ "| 1 |" ]] || false # conflict should return 1 + [[ "$output" =~ "| conflicts |" ]] || false + [[ "$output" =~ "| 1 |" ]] || false # conflict should return 1// [[ "$output" =~ "| Warning | 1105 | merge has unresolved conflicts or constraint violations |" ]] || false [[ "$output" =~ "| COUNT(*) |" ]] || false [[ "$output" =~ "| 1 |" ]] || false @@ -1335,16 +1333,16 @@ CREATE TABLE one_pk ( c2 BIGINT, PRIMARY KEY (pk1) ); -SELECT DOLT_COMMIT('-a', '-m', 'add tables'); -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_commit('-a', '-m', 'add tables'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,0,0); -SELECT DOLT_COMMIT('-a', '-m', 'changed main'); -SELECT DOLT_CHECKOUT('feature-branch'); +call dolt_commit('-a', '-m', 'changed main'); +call dolt_checkout('feature-branch'); INSERT INTO one_pk (pk1,c1,c2) VALUES (0,1,1); -SELECT DOLT_COMMIT('-a', '-m', 'changed feature branch'); -SELECT DOLT_CHECKOUT('main'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'changed feature branch'); +call dolt_checkout('main'); +call dolt_merge('feature-branch'); SHOW WARNINGS; SELECT COUNT(*) FROM dolt_conflicts where num_conflicts > 0; rollback; @@ -1360,11 +1358,11 @@ SQL @test "sql-merge: up-to-date branch does not error" { dolt commit -am "commit all changes" run dolt sql << SQL -SELECT DOLT_CHECKOUT('-b', 'feature-branch'); -SELECT DOLT_CHECKOUT('main'); +call dolt_checkout('-b', 'feature-branch'); +call dolt_checkout('main'); INSERT INTO test VALUES (3); -SELECT DOLT_COMMIT('-a', '-m', 'a commit'); -SELECT DOLT_MERGE('feature-branch'); +call dolt_commit('-a', '-m', 'a commit'); +call dolt_merge('feature-branch'); SHOW WARNINGS; SQL log_status_eq 0 diff --git a/integration-tests/bats/sql-multi-db.bats b/integration-tests/bats/sql-multi-db.bats index 1b084219a0..01cedc4bce 100644 --- a/integration-tests/bats/sql-multi-db.bats +++ b/integration-tests/bats/sql-multi-db.bats @@ -111,8 +111,7 @@ seed_repos_with_tables_with_use_statements() { cd .. run dolt sql --data-dir ./subremotes -b -q " USE repo2; - select dolt_fetch() as f;" -r csv + call dolt_fetch();" -r csv [ "$status" -eq 0 ] - [[ "${lines[1]}" =~ "f" ]] || false - [[ "${lines[2]}" =~ "1" ]] || false + [[ "${lines[1]}" =~ "Rows inserted: 0 Rows updated: 0 Rows deleted: 0" ]] || false } diff --git a/integration-tests/bats/sql-pull.bats b/integration-tests/bats/sql-pull.bats index db511aea53..c18ee10850 100644 --- a/integration-tests/bats/sql-pull.bats +++ b/integration-tests/bats/sql-pull.bats @@ -41,7 +41,7 @@ teardown() { @test "sql-pull: dolt_pull main" { cd repo2 - dolt sql -q "select dolt_pull('origin')" + dolt sql -q "call dolt_pull('origin')" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -71,7 +71,7 @@ teardown() { @test "sql-pull: dolt_pull custom remote" { cd repo2 - dolt sql -q "select dolt_pull('test-remote')" + dolt sql -q "call dolt_pull('test-remote')" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -92,7 +92,7 @@ teardown() { @test "sql-pull: dolt_pull default origin" { cd repo2 dolt remote remove test-remote - dolt sql -q "select dolt_pull()" + dolt sql -q "call dolt_pull()" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -114,7 +114,7 @@ teardown() { @test "sql-pull: dolt_pull default custom remote" { cd repo2 dolt remote remove origin - dolt sql -q "select dolt_pull()" + dolt sql -q "call dolt_pull()" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -135,8 +135,8 @@ teardown() { @test "sql-pull: dolt_pull up to date does not error" { cd repo2 - dolt sql -q "select dolt_pull('origin')" - dolt sql -q "select dolt_pull('origin')" + dolt sql -q "call dolt_pull('origin')" + dolt sql -q "call dolt_pull('origin')" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -157,7 +157,7 @@ teardown() { @test "sql-pull: dolt_pull unknown remote fails" { cd repo2 - run dolt sql -q "select dolt_pull('unknown')" + run dolt sql -q "call dolt_pull('unknown')" [ "$status" -eq 1 ] [[ "$output" =~ "unknown remote" ]] || false [[ ! "$output" =~ "panic" ]] || false @@ -174,7 +174,7 @@ teardown() { @test "sql-pull: dolt_pull unknown feature branch fails" { cd repo2 dolt checkout feature - run dolt sql -q "select dolt_pull('origin')" + run dolt sql -q "call dolt_pull('origin')" [ "$status" -eq 1 ] [[ "$output" =~ "You asked to pull from the remote 'origin', but did not specify a branch" ]] || false [[ ! "$output" =~ "panic" ]] || false @@ -203,7 +203,7 @@ teardown() { dolt push cd ../repo2 - dolt sql -q "select dolt_pull('origin')" + dolt sql -q "call dolt_pull('origin')" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -265,12 +265,12 @@ teardown() { dolt push -f origin main cd ../repo2 - run dolt sql -q "select dolt_pull('origin')" + run dolt sql -q "call dolt_pull('origin')" [ "$status" -eq 1 ] [[ ! "$output" =~ "panic" ]] || false [[ "$output" =~ "fetch failed; dataset head is not ancestor of commit" ]] || false - dolt sql -q "select dolt_pull('-f', 'origin')" + dolt sql -q "call dolt_pull('-f', 'origin')" run dolt log -n 1 [ "$status" -eq 0 ] @@ -314,7 +314,7 @@ teardown() { @test "sql-pull: dolt_pull squash" { skip "todo: support dolt pull --squash (cli too)" cd repo2 - dolt sql -q "select dolt_pull('--squash', 'origin')" + dolt sql -q "call dolt_pull('--squash', 'origin')" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -335,7 +335,7 @@ teardown() { @test "sql-pull: dolt_pull --noff flag" { cd repo2 - dolt sql -q "select dolt_pull('--no-ff', 'origin')" + dolt sql -q "call dolt_pull('--no-ff', 'origin')" dolt status run dolt log -n 1 [ "$status" -eq 0 ] @@ -367,7 +367,7 @@ teardown() { @test "sql-pull: empty remote name does not panic" { cd repo2 - dolt sql -q "select dolt_pull('')" + dolt sql -q "call dolt_pull('')" } @test "sql-pull: empty remote name does not panic on CALL" { @@ -378,7 +378,7 @@ teardown() { @test "sql-pull: dolt_pull dirty working set fails" { cd repo2 dolt sql -q "create table t2 (a int)" - run dolt sql -q "select dolt_pull('origin')" + run dolt sql -q "call dolt_pull('origin')" [ "$status" -eq 1 ] [[ "$output" =~ "cannot merge with uncommitted changes" ]] || false } @@ -398,7 +398,7 @@ teardown() { dolt tag cd ../repo2 - dolt sql -q "select dolt_pull('origin')" + dolt sql -q "call dolt_pull('origin')" run dolt tag [ "$status" -eq 0 ] [[ "$output" =~ "v1" ]] || false @@ -432,7 +432,7 @@ teardown() { dolt push origin v3 cd ../repo2 - dolt sql -q "select dolt_pull('origin')" + dolt sql -q "call dolt_pull('origin')" run dolt tag [ "$status" -eq 0 ] [[ "$output" =~ "v1" ]] || false @@ -524,7 +524,7 @@ teardown() { dolt push cd ../repo2 - dolt sql -q "select dolt_pull()" + dolt sql -q "call dolt_pull()" run dolt sql -q "show tables" -r csv [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 2 ] @@ -563,7 +563,7 @@ teardown() { dolt sql -q "insert into t1 values (2, 3)" dolt commit -am "add (2,3) to t1" - run dolt sql -q "select dolt_pull()" + run dolt sql -q "call dolt_pull()" [ "$status" -eq 0 ] run dolt log --oneline -n 1 diff --git a/integration-tests/bats/sql-push.bats b/integration-tests/bats/sql-push.bats index 839503c6b7..f98491b0dd 100644 --- a/integration-tests/bats/sql-push.bats +++ b/integration-tests/bats/sql-push.bats @@ -38,7 +38,7 @@ teardown() { @test "sql-push: dolt_push origin" { cd repo1 - dolt sql -q "select dolt_push('origin', 'main')" + dolt sql -q "call dolt_push('origin', 'main')" cd ../repo2 dolt pull origin @@ -77,7 +77,7 @@ teardown() { @test "sql-push: dolt_push custom remote" { cd repo1 - dolt sql -q "select dolt_push('test-remote', 'main')" + dolt sql -q "call dolt_push('test-remote', 'main')" cd ../repo2 dolt pull origin @@ -104,7 +104,7 @@ teardown() { @test "sql-push: dolt_push active branch" { skip "upstream state lost between sessions" cd repo1 - dolt sql -q "select dolt_push('origin')" + dolt sql -q "call dolt_push('origin')" cd ../repo2 dolt pull origin @@ -132,7 +132,7 @@ teardown() { @test "sql-push: dolt_push feature branch" { cd repo1 dolt checkout -b feature - dolt sql -q "select dolt_push('origin', 'feature')" + dolt sql -q "call dolt_push('origin', 'feature')" cd ../repo2 dolt fetch origin feature @@ -166,7 +166,7 @@ teardown() { [ "$status" -eq 1 ] [[ "$output" =~ "The current branch other has no upstream branch." ]] || false - dolt sql -q "select dolt_push('-u', 'origin', 'other')" + dolt sql -q "call dolt_push('-u', 'origin', 'other')" # upstream should be set still run dolt push [ "$status" -eq 0 ] @@ -182,7 +182,7 @@ teardown() { [[ "$output" =~ "The current branch other has no upstream branch." ]] || false dolt config --local --add push.autoSetUpRemote true - dolt sql -q "select dolt_push()" + dolt sql -q "call dolt_push()" # upstream should be set still run dolt push [ "$status" -eq 0 ] @@ -198,7 +198,7 @@ teardown() { [[ "$output" =~ "The current branch other has no upstream branch." ]] || false dolt config --local --add push.autoSetUpRemote TRUE - dolt sql -q "select dolt_push()" + dolt sql -q "call dolt_push()" # upstream should be set still run dolt push [ "$status" -eq 0 ] @@ -228,11 +228,11 @@ teardown() { dolt push origin main cd ../repo1 - run dolt sql -q "select dolt_push('origin', 'main')" + run dolt sql -q "call dolt_push('origin', 'main')" [ "$status" -eq 1 ] [[ "$output" =~ "the tip of your current branch is behind its remote counterpart" ]] || false - dolt sql -q "select dolt_push('--force', 'origin', 'main')" + dolt sql -q "call dolt_push('--force', 'origin', 'main')" } @test "sql-push: CALL dolt_push --force flag" { @@ -252,7 +252,7 @@ teardown() { @test "sql-push: push to unknown remote" { cd repo1 - run dolt sql -q "select dolt_push('unknown', 'main')" + run dolt sql -q "call dolt_push('unknown', 'main')" [ "$status" -eq 1 ] [[ "$output" =~ "unknown remote: 'unknown'" ]] || false } @@ -266,7 +266,7 @@ teardown() { @test "sql-push: push unknown branch" { cd repo1 - run dolt sql -q "select dolt_push('origin', 'unknown')" + run dolt sql -q "call dolt_push('origin', 'unknown')" [ "$status" -eq 1 ] [[ "$output" =~ "refspec not found: 'unknown'" ]] || false } @@ -280,7 +280,7 @@ teardown() { @test "sql-push: not specifying a branch throws an error" { cd repo1 - run dolt sql -q "select dolt_push('-u', 'origin')" + run dolt sql -q "call dolt_push('-u', 'origin')" [ "$status" -eq 1 ] [[ "$output" =~ "invalid set-upstream arguments" ]] || false } @@ -294,7 +294,7 @@ teardown() { @test "sql-push: pushing empty branch does not panic" { cd repo1 - run dolt sql -q "select dolt_push('origin', '')" + run dolt sql -q "call dolt_push('origin', '')" [ "$status" -eq 1 ] [[ "$output" =~ "invalid ref spec: ''" ]] || false } diff --git a/integration-tests/bats/sql-reset.bats b/integration-tests/bats/sql-reset.bats index 008512719f..5a05a41e86 100644 --- a/integration-tests/bats/sql-reset.bats +++ b/integration-tests/bats/sql-reset.bats @@ -22,7 +22,7 @@ teardown() { @test "sql-reset: DOLT_RESET --hard works on unstaged and staged table changes" { dolt sql -q "INSERT INTO test VALUES (1)" - run dolt sql -q "SELECT DOLT_RESET('--hard')" + run dolt sql -q "call dolt_reset('--hard')" [ $status -eq 0 ] run dolt status @@ -34,7 +34,7 @@ teardown() { dolt add . - run dolt sql -q "SELECT DOLT_RESET('--hard')" + run dolt sql -q "call dolt_reset('--hard')" [ $status -eq 0 ] run dolt status @@ -45,7 +45,7 @@ teardown() { dolt sql -q "INSERT INTO test VALUES (1)" # Reset to head results in clean main. - run dolt sql -q "SELECT DOLT_RESET('--hard', 'head');" + run dolt sql -q "call dolt_reset('--hard', 'head');" [ "$status" -eq 0 ] run dolt status @@ -130,7 +130,7 @@ teardown() { dolt docs upload LICENSE.md LICENSE.md dolt add . - run dolt sql -q "SELECT DOLT_RESET('--hard')" + run dolt sql -q "call dolt_reset('--hard')" [ $status -eq 0 ] dolt status @@ -171,7 +171,7 @@ teardown() { dolt sql -q "INSERT INTO test VALUES (1)" # Table should still be unstaged - run dolt sql -q "SELECT DOLT_RESET('--soft')" + run dolt sql -q "call dolt_reset('--soft')" [ $status -eq 0 ] run dolt status @@ -181,7 +181,7 @@ teardown() { dolt add . - run dolt sql -q "SELECT DOLT_RESET('--soft')" + run dolt sql -q "call dolt_reset('--soft')" [ $status -eq 0 ] run dolt status @@ -218,7 +218,7 @@ teardown() { dolt docs upload LICENSE.md LICENSE.md dolt add . - run dolt sql -q "SELECT DOLT_RESET('--soft')" + run dolt sql -q "call dolt_reset('--soft')" [ $status -eq 0 ] run dolt status @@ -243,7 +243,7 @@ teardown() { dolt sql -q "INSERT INTO test VALUES (1)" # Table should still be unstaged - run dolt sql -q "SELECT DOLT_RESET('test')" + run dolt sql -q "call dolt_reset('test')" run dolt status [ "$status" -eq 0 ] @@ -253,7 +253,7 @@ teardown() { dolt sql -q "CREATE TABLE test2 (pk int primary key);" dolt add . - run dolt sql -q "SELECT DOLT_RESET('test', 'test2')" + run dolt sql -q "call dolt_reset('test', 'test2')" run dolt status [ "$status" -eq 0 ] @@ -288,7 +288,7 @@ teardown() { @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 "SELECT DOLT_RESET('test')" + run dolt sql -q "call dolt_reset('test')" [ "$status" -eq 0 ] run dolt status @@ -299,7 +299,7 @@ teardown() { # Add and unstage the table with a soft reset. Make sure the same data exists. dolt add . - run dolt sql -q "SELECT DOLT_RESET('test')" + run dolt sql -q "call dolt_reset('test')" [ "$status" -eq 0 ] run dolt status @@ -312,7 +312,7 @@ teardown() { [[ "$output" =~ 1 ]] || false # Do a hard reset and validate the insert was wiped properly - run dolt sql -q "SELECT DOLT_RESET('--hard')" + run dolt sql -q "call dolt_reset('--hard')" run dolt status [ "$status" -eq 0 ] @@ -369,7 +369,7 @@ CREATE TABLE test2 ( pk int primary key ); SQL - dolt sql -q "SELECT DOLT_RESET('--hard');" + dolt sql -q "call dolt_reset('--hard');" run dolt status [ "$status" -eq 0 ] @@ -377,7 +377,7 @@ SQL [[ "$output" =~ ([[:space:]]*new table:[[:space:]]*test2) ]] || false dolt add . - dolt sql -q "SELECT DOLT_RESET('--hard');" + dolt sql -q "call dolt_reset('--hard');" run dolt status [ "$status" -eq 0 ] @@ -410,7 +410,7 @@ SQL @test "sql-reset: No rows in dolt_diff table after DOLT_RESET('--hard') on committed table." { run dolt sql << SQL INSERT INTO test VALUES (1); -SELECT DOLT_RESET('--hard'); +call dolt_reset('--hard'); SELECT count(*)=0 FROM dolt_diff_test; SQL [ $status -eq 0 ] @@ -432,7 +432,7 @@ SQL @test "sql-reset: No rows in dolt_status table after DOLT_RESET('--hard') on committed table." { run dolt sql << SQL INSERT INTO test VALUES (1); -SELECT DOLT_RESET('--hard'); +call dolt_reset('--hard'); SELECT count(*)=0 FROM dolt_status; SQL [ $status -eq 0 ] @@ -454,7 +454,7 @@ SQL head_hash=$(get_head_commit) run dolt sql << SQL INSERT INTO test VALUES (1); -SELECT DOLT_RESET('--hard'); +call dolt_reset('--hard'); SELECT $head_variable; SQL @@ -480,7 +480,7 @@ SQL INSERT INTO test VALUES (1); SQL - dolt sql -q "SELECT DOLT_RESET('test');" + dolt sql -q "call dolt_reset('test');" run dolt sql -q "SELECT * FROM dolt_status;" [ $status -eq 0 ] @@ -506,8 +506,8 @@ SQL run dolt sql << SQL INSERT INTO test VALUES (1); -SELECT DOLT_ADD('.'); -SELECT DOLT_RESET('test'); +call dolt_add('.'); +call dolt_reset('test'); SELECT $working_hash_var SQL @@ -516,7 +516,7 @@ SQL # 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 "SELECT DOLT_RESET('--hard');" + run dolt sql -q "call dolt_reset('--hard');" [ $status -eq 0 ] run dolt sql -q "SELECT $working_hash_var" @@ -533,8 +533,8 @@ SQL run dolt sql << SQL INSERT INTO test VALUES (1); -SELECT DOLT_ADD('.'); -SELECT DOLT_RESET('test'); +call dolt_add('.'); +call dolt_reset('test'); SELECT $working_hash_var SQL diff --git a/integration-tests/bats/sql-server.bats b/integration-tests/bats/sql-server.bats index 448e38a4e1..7407e211a8 100644 --- a/integration-tests/bats/sql-server.bats +++ b/integration-tests/bats/sql-server.bats @@ -257,18 +257,18 @@ SQL dolt sql --user=dolt -q "CALL DOLT_ADD('.')" # check that dolt_commit works properly when autocommit is on - run dolt sql --user=dolt -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1')" + run dolt sql --user=dolt -q "call dolt_commit('-a', '-m', 'Commit1')" [ "$status" -eq 0 ] # check that dolt_commit throws error now that there are no working set changes. - run dolt sql --user=dolt -q "SELECT DOLT_COMMIT('-a', '-m', 'Commit1')" + run dolt sql --user=dolt -q "call dolt_commit('-a', '-m', 'Commit1')" [ "$status" -eq 1 ] # Make a change to the working set but not the staged set. run dolt sql --user=dolt -q "INSERT INTO one_pk (pk,c1,c2) VALUES (2,2,2),(3,3,3)" # check that dolt_commit throws error now that there are no staged changes. - run dolt sql --user=dolt -q "SELECT DOLT_COMMIT('-m', 'Commit1')" + run dolt sql --user=dolt -q "call dolt_commit('-m', 'Commit1')" [ "$status" -eq 1 ] run dolt log @@ -577,14 +577,14 @@ SQL pk int primary key ); INSERT INTO test VALUES (0),(1),(2); - SELECT DOLT_ADD('.'); - SELECT DOLT_COMMIT('-m', 'Step 1'); - SELECT DOLT_CHECKOUT('-b', 'feature-branch'); + call dolt_add('.'); + call dolt_commit('-m', 'Step 1'); + call dolt_checkout('-b', 'feature-branch'); INSERT INTO test VALUES (3); UPDATE test SET pk=1000 WHERE pk=0; - SELECT DOLT_COMMIT('-a', '-m', 'this is a ff'); - SELECT DOLT_CHECKOUT('main'); - SELECT DOLT_MERGE('feature-branch'); + call dolt_commit('-a', '-m', 'this is a ff'); + call dolt_checkout('main'); + call dolt_merge('feature-branch'); " run dolt sql-client -P $PORT -u dolt --use-db repo1 -q "SELECT * FROM test" @@ -836,7 +836,7 @@ SQL start_sql_server repo1 run dolt sql-client -P $PORT -u dolt --use-db repo1 -q ' - select dolt_checkout("new"); + call dolt_checkout("new"); CREATE TABLE t (a int primary key, b int); INSERT INTO t VALUES (2,2),(3,3);' diff --git a/integration-tests/bats/sql-shell.bats b/integration-tests/bats/sql-shell.bats index c265639dab..7d1eb03831 100644 --- a/integration-tests/bats/sql-shell.bats +++ b/integration-tests/bats/sql-shell.bats @@ -813,7 +813,7 @@ SQL [ $status -eq 0 ] [[ "$output" =~ "active_branch()" ]] || false [[ "$output" =~ "main" ]] || false - run dolt sql <<< "select dolt_checkout('-b', 'tmp_br') as co; select active_branch()" + run dolt sql <<< "call dolt_checkout('-b', 'tmp_br'); select active_branch()" [ $status -eq 0 ] [[ "$output" =~ "active_branch()" ]] || false [[ "$output" =~ "tmp_br" ]] || false diff --git a/integration-tests/bats/sql.bats b/integration-tests/bats/sql.bats index e2a0c55d47..423e7260e3 100755 --- a/integration-tests/bats/sql.bats +++ b/integration-tests/bats/sql.bats @@ -1291,7 +1291,7 @@ USE \`dolt_repo_$$/feature-branch\`; CREATE TABLE table_a(x int primary key); CREATE TABLE table_b(x int primary key); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'two new tables'); +call dolt_commit('-a', '-m', 'two new tables'); SQL run dolt sql -q "show tables" -r csv @@ -1317,7 +1317,7 @@ USE test1; CREATE TABLE table_a(x int primary key); CALL DOLT_ADD('.'); insert into table_a values (1), (2); -SELECT DOLT_COMMIT('-a', '-m', 'created table_a'); +call dolt_commit('-a', '-m', 'created table_a'); SQL cd test1 @@ -1380,7 +1380,7 @@ USE test1; CREATE TABLE table_a(x int primary key); CALL DOLT_ADD('.'); insert into table_a values (1), (2); -SELECT DOLT_COMMIT('-a', '-m', 'created table_a'); +call dolt_commit('-a', '-m', 'created table_a'); SQL cd test1 @@ -1474,7 +1474,7 @@ SQL set @@dolt_repo_$$_head_ref = 'feature-branch'; CREATE TABLE test (x int primary key); CALL DOLT_ADD('.'); -SELECT DOLT_COMMIT('-a', '-m', 'new table'); +call dolt_commit('-a', '-m', 'new table'); SQL run dolt sql -q "show tables" -r csv @@ -1492,7 +1492,7 @@ SQL dolt sql < 2 }, { "insert into test (pk, `value`) values (0,0)" => 1 }, { "select * from test" => 1 }, - {"select dolt_add('-A');" => 1 }, - {"select dolt_commit('-m', 'my commit')" => 1}, - {"select dolt_checkout('-b', 'mybranch')" => 1 }, + {"call dolt_add('-A');" => 1 }, + {"call dolt_commit('-m', 'my commit')" => 1}, + {"call dolt_checkout('-b', 'mybranch')" => 1 }, {"insert into test (pk, `value`) values (1,1)" => 1 }, - {"select dolt_commit('-a', '-m', 'my commit2')" => 1 }, - {"select dolt_checkout('main')" => 1 }, - {"select dolt_merge('mybranch')" => 1 }, + {"call dolt_commit('-a', '-m', 'my commit2')" => 1 }, + {"call dolt_checkout('main')" => 1 }, + {"call dolt_merge('mybranch')" => 1 }, {"select COUNT(*) FROM dolt_log" => 1 }, ]; diff --git a/integration-tests/mysql-client-tests/python/mysql.connector-test.py b/integration-tests/mysql-client-tests/python/mysql.connector-test.py index 0e847e4569..8ad318ec11 100644 --- a/integration-tests/mysql-client-tests/python/mysql.connector-test.py +++ b/integration-tests/mysql-client-tests/python/mysql.connector-test.py @@ -16,14 +16,14 @@ QUERY_RESPONSE = [ {"select * from test; ": [(0, 0)]}, {"select * from test; ": [(0, 0)]}, # Test the Dolt SQL functions - {"select dolt_add('-A');": [(0,)]}, - {"select dolt_commit('-m', 'my commit')": [('',)]}, + {"call dolt_add('-A');": [(0,)]}, + {"call dolt_commit('-m', 'my commit')": [('',)]}, {"select COUNT(*) FROM dolt_log": [(2,)]}, - {"select dolt_checkout('-b', 'mybranch')": [(0,)]}, + {"call dolt_checkout('-b', 'mybranch')": [(0,)]}, {"insert into test (pk, `value`) values (1,1)": []}, - {"select dolt_commit('-a', '-m', 'my commit2')": [('',)]}, - {"select dolt_checkout('main')": [(0,)]}, - {"select dolt_merge('mybranch')": [(0,)]}, + {"call dolt_commit('-a', '-m', 'my commit2')": [('',)]}, + {"call dolt_checkout('main')": [(0,)]}, + {"call dolt_merge('mybranch')": [(1,0,)]}, {"select COUNT(*) FROM dolt_log": [(3,)]}, ] diff --git a/integration-tests/mysql-client-tests/python/pymysql-test.py b/integration-tests/mysql-client-tests/python/pymysql-test.py index 72195d642a..8ec59adba8 100644 --- a/integration-tests/mysql-client-tests/python/pymysql-test.py +++ b/integration-tests/mysql-client-tests/python/pymysql-test.py @@ -9,14 +9,14 @@ QUERY_RESPONSE = [ )}, {"insert into test (pk, `value`) values (0,0)": ()}, {"select * from test": ((0, 0),)}, - {"select dolt_add('-A');": ((0,),)}, - {"select dolt_commit('-m', 'my commit')": (('',),)}, + {"call dolt_add('-A');": ((0,),)}, + {"call dolt_commit('-m', 'my commit')": (('',),)}, {"select COUNT(*) FROM dolt_log": ((2,),)}, - {"select dolt_checkout('-b', 'mybranch')": ((0,),)}, + {"call dolt_checkout('-b', 'mybranch')": ((0,),)}, {"insert into test (pk, `value`) values (1,1)": ()}, - {"select dolt_commit('-a', '-m', 'my commit2')": (('',),)}, - {"select dolt_checkout('main')": ((0,),)}, - {"select dolt_merge('mybranch')": ((0,),)}, + {"call dolt_commit('-a', '-m', 'my commit2')": (('',),)}, + {"call dolt_checkout('main')": ((0,),)}, + {"call dolt_merge('mybranch')": ((1,0,),)}, {"select COUNT(*) FROM dolt_log": ((3,),)}, ] diff --git a/integration-tests/mysql-client-tests/python/sqlalchemy-test.py b/integration-tests/mysql-client-tests/python/sqlalchemy-test.py index 155a8ed808..dc1c0669bb 100644 --- a/integration-tests/mysql-client-tests/python/sqlalchemy-test.py +++ b/integration-tests/mysql-client-tests/python/sqlalchemy-test.py @@ -13,14 +13,14 @@ QUERY_RESPONSE = [ ]}, {"insert into test (pk, `value`) values (0,0)": ()}, {"select * from test": [(0, 0)]}, - {"select dolt_add('-A');": [(0,)]}, - {"select dolt_commit('-m', 'my commit')": [('',)]}, + {"call dolt_add('-A');": [(0,)]}, + {"call dolt_commit('-m', 'my commit')": [('',)]}, {"select COUNT(*) FROM dolt_log": [(2,)]}, - {"select dolt_checkout('-b', 'mybranch')": [(0,)]}, + {"call dolt_checkout('-b', 'mybranch')": [(0,)]}, {"insert into test (pk, `value`) values (1,1)": []}, - {"select dolt_commit('-a', '-m', 'my commit2')": [('',)]}, - {"select dolt_checkout('main')": [(0,)]}, - {"select dolt_merge('mybranch')": [(0,)]}, + {"call dolt_commit('-a', '-m', 'my commit2')": [('',)]}, + {"call dolt_checkout('main')": [(0,)]}, + {"call dolt_merge('mybranch')": [(1,0,)]}, {"select COUNT(*) FROM dolt_log": [(3,)]}, ] diff --git a/integration-tests/mysql-client-tests/r/rmariadb-test.r b/integration-tests/mysql-client-tests/r/rmariadb-test.r index 7978f6b76a..16903185a8 100644 --- a/integration-tests/mysql-client-tests/r/rmariadb-test.r +++ b/integration-tests/mysql-client-tests/r/rmariadb-test.r @@ -56,13 +56,13 @@ if (!isTRUE(all.equal(want, got))) { quit(1) } -dolt_queries = list("SELECT DOLT_ADD('-A')", - "select dolt_commit('-m', 'my commit')", - "select dolt_checkout('-b', 'mybranch')", +dolt_queries = list("call DOLT_ADD('-A')", + "call dolt_commit('-m', 'my commit')", + "call dolt_checkout('-b', 'mybranch')", "insert into test (pk, `value`) values (2,2)", - "select dolt_commit('-a', '-m', 'my commit2')", - "select dolt_checkout('main')", - "select dolt_merge('mybranch')") + "call dolt_commit('-a', '-m', 'my commit2')", + "call dolt_checkout('main')", + "call dolt_merge('mybranch')") for(i in 1:length(dolt_queries)) { q = dolt_queries[[i]] diff --git a/integration-tests/mysql-client-tests/r/rmysql-test.r b/integration-tests/mysql-client-tests/r/rmysql-test.r index f493dfddbe..9e5a60f677 100644 --- a/integration-tests/mysql-client-tests/r/rmysql-test.r +++ b/integration-tests/mysql-client-tests/r/rmysql-test.r @@ -37,13 +37,13 @@ for(i in 1:length(queries)) { } } -dolt_queries = list("SELECT DOLT_ADD('-A')", - "select dolt_commit('-m', 'my commit')", - "select dolt_checkout('-b', 'mybranch')", +dolt_queries = list("call DOLT_ADD('-A')", + "call dolt_commit('-m', 'my commit')", + "call dolt_checkout('-b', 'mybranch')", "insert into test (pk, `value`) values (1,1)", - "select dolt_commit('-a', '-m', 'my commit2')", - "select dolt_checkout('main')", - "select dolt_merge('mybranch')") + "call dolt_commit('-a', '-m', 'my commit2')", + "call dolt_checkout('main')", + "call dolt_merge('mybranch')") for(i in 1:length(dolt_queries)) { q = dolt_queries[[i]] diff --git a/integration-tests/mysql-client-tests/ruby/ruby-mysql-test.rb b/integration-tests/mysql-client-tests/ruby/ruby-mysql-test.rb index e2ebe3cb8b..110f5a4bc7 100644 --- a/integration-tests/mysql-client-tests/ruby/ruby-mysql-test.rb +++ b/integration-tests/mysql-client-tests/ruby/ruby-mysql-test.rb @@ -12,14 +12,14 @@ queries = [ "select * from test", "insert into test (pk, `value`) values (0,0)", "select * from test", - "select dolt_add('-A');", - "select dolt_commit('-m', 'my commit')", + "call dolt_add('-A');", + "call dolt_commit('-m', 'my commit')", "select COUNT(*) FROM dolt_log", - "select dolt_checkout('-b', 'mybranch')", + "call dolt_checkout('-b', 'mybranch')", "insert into test (pk, `value`) values (1,1)", - "select dolt_commit('-a', '-m', 'my commit2')", - "select dolt_checkout('main')", - "select dolt_merge('mybranch')", + "call dolt_commit('-a', '-m', 'my commit2')", + "call dolt_checkout('main')", + "call dolt_merge('mybranch')", "select COUNT(*) FROM dolt_log", ]