mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-22 02:50:04 -05:00
Fixed bug adding primary key, not null constraint wasn't getting applied in some cases
This commit is contained in:
@@ -80,34 +80,29 @@ func TestSingleScript(t *testing.T) {
|
||||
|
||||
var scripts = []queries.ScriptTest{
|
||||
{
|
||||
Name: "Multialter DDL with ADD/DROP Primary Key",
|
||||
Name: "Drop and add primary key on two branches converges to same schema",
|
||||
SetUpScript: []string{
|
||||
"CREATE TABLE t(pk int primary key, v1 int)",
|
||||
"create table t1 (i int);",
|
||||
"call dolt_commit('-am', 't1 table')",
|
||||
"call dolt_checkout('-b', 'b1')",
|
||||
"alter table t1 add primary key(i)",
|
||||
"alter table t1 drop primary key",
|
||||
"alter table t1 add primary key(i)",
|
||||
"alter table t1 drop primary key",
|
||||
"alter table t1 add primary key(i)",
|
||||
"call dolt_commit('-am', 'b1 primary key changes')",
|
||||
"call dolt_checkout('main')",
|
||||
"alter table t1 add primary key(i)",
|
||||
"call dolt_commit('-am', 'main primary key change')",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "ALTER TABLE t ADD COLUMN (v2 int), drop primary key, add primary key (v2)",
|
||||
Expected: []sql.Row{{sql.NewOkResult(0)}},
|
||||
Query: "call dolt_merge('b1')",
|
||||
Expected: []sql.Row{{1}},
|
||||
},
|
||||
{
|
||||
Query: "DESCRIBE t",
|
||||
Expected: []sql.Row{
|
||||
{"pk", "int", "NO", "", "", ""},
|
||||
{"v1", "int", "YES", "", "", ""},
|
||||
{"v2", "int", "NO", "PRI", "", ""},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "ALTER TABLE t ADD COLUMN (v3 int), drop primary key, add primary key (notacolumn)",
|
||||
ExpectedErr: sql.ErrKeyColumnDoesNotExist,
|
||||
},
|
||||
{
|
||||
Query: "DESCRIBE t",
|
||||
Expected: []sql.Row{
|
||||
{"pk", "int", "NO", "", "", ""},
|
||||
{"v1", "int", "YES", "", "", ""},
|
||||
{"v2", "int", "NO", "PRI", "", ""},
|
||||
},
|
||||
Query: "select count(*) from dolt_conflicts",
|
||||
Expected: []sql.Row{{0}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -985,6 +985,33 @@ var MergeScripts = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Drop and add primary key on two branches converges to same schema",
|
||||
SetUpScript: []string{
|
||||
"create table t1 (i int);",
|
||||
"call dolt_commit('-am', 't1 table')",
|
||||
"call dolt_checkout('-b', 'b1')",
|
||||
"alter table t1 add primary key(i)",
|
||||
"alter table t1 drop primary key",
|
||||
"alter table t1 add primary key(i)",
|
||||
"alter table t1 drop primary key",
|
||||
"alter table t1 add primary key(i)",
|
||||
"call dolt_commit('-am', 'b1 primary key changes')",
|
||||
"call dolt_checkout('main')",
|
||||
"alter table t1 add primary key(i)",
|
||||
"call dolt_commit('-am', 'main primary key change')",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "call dolt_merge('b1')",
|
||||
Expected: []sql.Row{{1}},
|
||||
},
|
||||
{
|
||||
Query: "select count(*) from dolt_conflicts",
|
||||
Expected: []sql.Row{{0}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var DoltReset = []queries.ScriptTest{
|
||||
|
||||
@@ -124,7 +124,7 @@ func ToDoltSchema(
|
||||
// ToDoltCol returns the dolt column corresponding to the SQL column given
|
||||
func ToDoltCol(tag uint64, col *sql.Column) (schema.Column, error) {
|
||||
var constraints []schema.ColConstraint
|
||||
if !col.Nullable {
|
||||
if !col.Nullable || col.PrimaryKey {
|
||||
constraints = append(constraints, schema.NotNullConstraint{})
|
||||
}
|
||||
typeInfo, err := typeinfo.FromSqlType(col.Type)
|
||||
|
||||
Reference in New Issue
Block a user