mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-27 15:41:44 -05:00
more tests, set feature version on merge and stage
This commit is contained in:
@@ -16,15 +16,16 @@ package doltdb_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/commands"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/commands"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -68,13 +69,6 @@ type fvUser struct {
|
||||
var NewClient = fvUser{vers: newVersion}
|
||||
var OldClient = fvUser{vers: oldVersion}
|
||||
|
||||
func TestFeatureVersionSanityCheck(t *testing.T) {
|
||||
assert.Equal(t, DoltFeatureVersionCopy, doltdb.DoltFeatureVersion)
|
||||
|
||||
assert.NotEqual(t, DoltFeatureVersionCopy, oldVersion)
|
||||
assert.NotEqual(t, DoltFeatureVersionCopy, newVersion)
|
||||
}
|
||||
|
||||
func TestFeatureVersion(t *testing.T) {
|
||||
|
||||
tests := []fvTest{
|
||||
@@ -163,6 +157,16 @@ func TestFeatureVersion(t *testing.T) {
|
||||
},
|
||||
expVer: oldVersion,
|
||||
},
|
||||
{
|
||||
name: "reset --hard reverts feature version",
|
||||
setup: []fvCommand{
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
|
||||
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table"}},
|
||||
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
|
||||
{NewClient, commands.ResetCmd{}, args{"--hard"}},
|
||||
},
|
||||
expVer: oldVersion,
|
||||
},
|
||||
{
|
||||
name: "new client writes to table, locking out old client",
|
||||
setup: []fvCommand{
|
||||
@@ -178,6 +182,72 @@ func TestFeatureVersion(t *testing.T) {
|
||||
},
|
||||
expVer: newVersion,
|
||||
},
|
||||
{
|
||||
name: "old client cannot checkout branch written by new client",
|
||||
setup: []fvCommand{
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
|
||||
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table test"}},
|
||||
{OldClient, commands.BranchCmd{}, args{"other"}},
|
||||
{NewClient, commands.CheckoutCmd{}, args{"other"}},
|
||||
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (10), (11);"}},
|
||||
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "added data to test"}},
|
||||
{NewClient, commands.CheckoutCmd{}, args{"master"}},
|
||||
// OldClient can read from master
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "SELECT * FROM test"}},
|
||||
},
|
||||
errCmds: []fvCommand{
|
||||
// old client can't checkout 'other'
|
||||
{OldClient, commands.CheckoutCmd{}, args{"other"}},
|
||||
// old client can't merge 'other'
|
||||
{OldClient, commands.MergeCmd{}, args{"other"}},
|
||||
},
|
||||
expVer: oldVersion,
|
||||
},
|
||||
{
|
||||
name: "fast-forward merge writes feature version",
|
||||
setup: []fvCommand{
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
|
||||
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table test"}},
|
||||
{OldClient, commands.BranchCmd{}, args{"other"}},
|
||||
{NewClient, commands.CheckoutCmd{}, args{"other"}},
|
||||
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (10), (11);"}},
|
||||
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "added data to test"}},
|
||||
{NewClient, commands.CheckoutCmd{}, args{"master"}},
|
||||
{NewClient, commands.MergeCmd{}, args{"other"}},
|
||||
},
|
||||
errCmds: []fvCommand{
|
||||
// old client can't write
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (2);"}},
|
||||
// old client can't read
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "SELECT * FROM test;"}},
|
||||
},
|
||||
expVer: newVersion,
|
||||
},
|
||||
{
|
||||
name: "3way merge writes feature version",
|
||||
setup: []fvCommand{
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "CREATE TABLE test (pk int PRIMARY KEY);"}},
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (0);"}},
|
||||
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "created table test"}},
|
||||
{OldClient, commands.BranchCmd{}, args{"other"}},
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (1);"}},
|
||||
{OldClient, commands.CommitCmd{}, args{"-a", "-m", "added another row"}},
|
||||
{NewClient, commands.CheckoutCmd{}, args{"other"}},
|
||||
{NewClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (10), (11);"}},
|
||||
{NewClient, commands.CommitCmd{}, args{"-a", "-m", "added data to test"}},
|
||||
{NewClient, commands.CheckoutCmd{}, args{"master"}},
|
||||
{NewClient, commands.MergeCmd{}, args{"other"}},
|
||||
},
|
||||
errCmds: []fvCommand{
|
||||
// old client can't write
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "INSERT INTO test VALUES (2);"}},
|
||||
// old client can't read
|
||||
{OldClient, commands.SqlCmd{}, args{"-q", "SELECT * FROM test;"}},
|
||||
},
|
||||
expVer: newVersion,
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -201,13 +271,16 @@ func TestFeatureVersion(t *testing.T) {
|
||||
doltdb.DoltFeatureVersion = newVersion
|
||||
defer func() { doltdb.DoltFeatureVersion = DoltFeatureVersionCopy }()
|
||||
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
assertFeatureVersion := func(r *doltdb.RootValue) {
|
||||
act, ok, err := r.GetFeatureVersion(ctx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, test.expVer, act)
|
||||
}
|
||||
|
||||
act, ok, err := root.GetFeatureVersion(ctx)
|
||||
working, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, test.expVer, act)
|
||||
assertFeatureVersion(working)
|
||||
})
|
||||
|
||||
// ensure |doltdb.DoltFeatureVersion| was restored
|
||||
|
||||
@@ -103,12 +103,12 @@ func (root *RootValue) GetFeatureVersion(ctx context.Context) (ver FeatureVersio
|
||||
}
|
||||
|
||||
func (root *RootValue) SetFeatureVersion(ctx context.Context) (*RootValue, error) {
|
||||
st, err := root.valueSt.Set(featureVersKey, types.Int(DoltFeatureVersion))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
st, err := root.valueSt.Set(featureVersKey, types.Int(DoltFeatureVersion))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newRootValue(root.vrw, st)
|
||||
return newRootValue(root.vrw, st)
|
||||
}
|
||||
|
||||
func (root *RootValue) HasTable(ctx context.Context, tName string) (bool, error) {
|
||||
|
||||
+28
-5
@@ -64,31 +64,26 @@ func StageAllTables(ctx context.Context, dbData env.DbData) error {
|
||||
drw := dbData.Drw
|
||||
|
||||
staged, err := env.StagedRoot(ctx, ddb, rsr)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
working, err := env.WorkingRoot(ctx, ddb, rsr)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
docs, err := drw.GetDocsOnDisk()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
working, err = doltdocs.UpdateRootWithDocs(ctx, working, docs)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tbls, err := doltdb.UnionTableNames(ctx, staged, working)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -118,6 +113,11 @@ func stageTables(ctx context.Context, db *doltdb.DoltDB, rsw env.RepoStateWriter
|
||||
return err
|
||||
}
|
||||
|
||||
staged, err = maybeBumpFeatureVersion(ctx, staged, working)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := env.UpdateWorkingRoot(ctx, db, rsw, working); err == nil {
|
||||
if sh, err := env.UpdateStagedRoot(ctx, db, rsw, staged); err == nil {
|
||||
err = rsw.SetStagedHash(ctx, sh)
|
||||
@@ -176,6 +176,29 @@ func checkTablesForConflicts(ctx context.Context, tbls []string, working *doltdb
|
||||
return working, nil
|
||||
}
|
||||
|
||||
// maybeBumpFeatureVersion compares the FeatureVersions of |staged| and |working| and
|
||||
// updates |staged|'s FeatureVersion if they differ.
|
||||
func maybeBumpFeatureVersion(ctx context.Context, staged, working *doltdb.RootValue) (*doltdb.RootValue, error) {
|
||||
sfv, ok1, err := staged.GetFeatureVersion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wfv, ok2, err := working.GetFeatureVersion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ok1 != ok2 || sfv != wfv {
|
||||
staged, err = staged.SetFeatureVersion(ctx)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return staged, nil
|
||||
}
|
||||
|
||||
// ValidateTables checks that all tables passed exist in at least one of the roots passed.
|
||||
func ValidateTables(ctx context.Context, tbls []string, roots ...*doltdb.RootValue) error {
|
||||
var missing []string
|
||||
|
||||
@@ -820,7 +820,11 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
|
||||
}
|
||||
|
||||
newRoot, err = newRoot.UpdateSuperSchemasFromOther(ctx, unconflicted, theirRoot)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
newRoot, err = newRoot.SetFeatureVersion(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user