mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-21 03:24:13 -05:00
Fix NULL default bug when merging branches with different schemas
This commit is contained in:
@@ -644,6 +644,41 @@ var SchemaChangeTestsBasicCases = []MergeScriptTest{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// One branch adds a new column with NULL as default
|
||||
// Other branch has new rows which need to be migrated.
|
||||
// Created values are NULL, not "NULL".
|
||||
Name: "creating new column to replace ancestor column",
|
||||
AncSetUpScript: []string{
|
||||
"CREATE table t (pk int primary key);",
|
||||
"INSERT into t values (1), (2);",
|
||||
},
|
||||
RightSetUpScript: []string{
|
||||
"ALTER TABLE t ADD new_col LONGTEXT DEFAULT NULL",
|
||||
"INSERT INTO t VALUES (3, 'three'), (4, 'four');",
|
||||
},
|
||||
LeftSetUpScript: []string{
|
||||
// Put rows on main which are not in the right branch.
|
||||
"INSERT INTO t VALUES (5), (6)",
|
||||
},
|
||||
Assertions: []queries.ScriptTestAssertion{
|
||||
{
|
||||
Query: "call dolt_merge('right');",
|
||||
Expected: []sql.Row{{doltCommit, 0, 0, "merge successful"}},
|
||||
},
|
||||
{
|
||||
Query: "select * from t;",
|
||||
Expected: []sql.Row{
|
||||
{1, nil},
|
||||
{2, nil},
|
||||
{3, "three"},
|
||||
{4, "four"},
|
||||
{5, nil},
|
||||
{6, nil},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var SchemaChangeTestsCollations = []MergeScriptTest{
|
||||
|
||||
@@ -193,7 +193,7 @@ func GenerateCreateTableIndentedColumnDefinition(col schema.Column, tableCollati
|
||||
var defaultVal, genVal, onUpdateVal *sql.ColumnDefaultValue
|
||||
if col.Default != "" {
|
||||
// hacky way to determine if column default is an expression
|
||||
if col.Default[0] != '(' && col.Default[len(col.Default)-1] != ')' && col.Default[0] != '\'' && col.Default[len(col.Default)-1] != '\'' {
|
||||
if col.Default[0] != '(' && col.Default[len(col.Default)-1] != ')' && col.Default[0] != '\'' && col.Default[len(col.Default)-1] != '\'' && col.Default != "NULL" {
|
||||
col.Default = fmt.Sprintf("'%s'", col.Default)
|
||||
}
|
||||
defaultVal = sql.NewUnresolvedColumnDefaultValue(col.Default)
|
||||
|
||||
Reference in New Issue
Block a user