Skip to content

Fix NULL default bug when merging branches with different schemas #9158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries_schema_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/sqlfmt/schema_fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading