-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
VReplication/OnlineDDL: reordering enum values #15103
Merged
shlomi-noach
merged 8 commits into
vitessio:main
from
planetscale:onlineddl-vrepl-enum-reorder
Feb 25, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0d16bd4
Vreplication/OnlineDDL: reordering enum values
shlomi-noach 4eb2a6c
just red, green. blue
shlomi-noach 03f52b9
move into correct path
shlomi-noach 3605195
go/test/endtoend/onlineddl/vrepl_suite/ changes should kick CI
shlomi-noach 1196b06
resolved conflict
shlomi-noach d01ead2
OnlineDDL: map ENUM's value to text whether the columns is converted …
shlomi-noach f65a0a2
do not mark SetEnumToTextConversion
shlomi-noach 4fd765e
schemadiff: default EnumReorderStrategy is EnumReorderStrategyAllow
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
go/test/endtoend/onlineddl/vrepl_suite/testdata/enum-reorder/alter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
change e e enum('blue', 'green', 'red') not null |
26 changes: 26 additions & 0 deletions
26
go/test/endtoend/onlineddl/vrepl_suite/testdata/enum-reorder/create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
drop table if exists onlineddl_test; | ||
create table onlineddl_test ( | ||
id int auto_increment, | ||
i int not null, | ||
e enum('red', 'green', 'blue') not null, | ||
primary key(id) | ||
) auto_increment=1; | ||
|
||
insert into onlineddl_test values (null, 11, 'red'); | ||
insert into onlineddl_test values (null, 13, 'green'); | ||
insert into onlineddl_test values (null, 17, 'blue'); | ||
|
||
drop event if exists onlineddl_test; | ||
delimiter ;; | ||
create event onlineddl_test | ||
on schedule every 1 second | ||
starts current_timestamp | ||
ends current_timestamp + interval 60 second | ||
on completion not preserve | ||
enable | ||
do | ||
begin | ||
insert into onlineddl_test values (null, 211, 'red'); | ||
insert into onlineddl_test values (null, 213, 'green'); | ||
insert into onlineddl_test values (null, 217, 'blue'); | ||
end ;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,248 @@ func TestGetSharedColumns(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added test is mostly irrelevant to the changes in this PR, but while writing the PR I noticed how this was missing. |
||
func TestGetExpandedColumnNames(t *testing.T) { | ||
var ( | ||
columnsA = &ColumnList{ | ||
columns: []Column{ | ||
{ | ||
Name: "c1", | ||
IsNullable: true, | ||
}, | ||
{ | ||
Name: "c2", | ||
IsNullable: true, | ||
}, | ||
{ | ||
Name: "c3", | ||
IsNullable: false, | ||
}, | ||
}, | ||
Ordinals: ColumnsMap{}, | ||
} | ||
columnsB = &ColumnList{ | ||
columns: []Column{ | ||
{ | ||
Name: "c1", | ||
IsNullable: true, | ||
}, | ||
{ | ||
Name: "c2", | ||
IsNullable: false, | ||
}, | ||
{ | ||
Name: "c3", | ||
IsNullable: true, | ||
}, | ||
}, | ||
Ordinals: ColumnsMap{}, | ||
} | ||
) | ||
tcases := []struct { | ||
name string | ||
sourceCol Column | ||
targetCol Column | ||
expanded bool | ||
}{ | ||
{ | ||
"both nullable", | ||
Column{ | ||
IsNullable: true, | ||
}, | ||
Column{ | ||
IsNullable: true, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"nullable to non nullable", | ||
Column{ | ||
IsNullable: true, | ||
}, | ||
Column{ | ||
IsNullable: false, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"non nullable to nullable", | ||
Column{ | ||
IsNullable: false, | ||
}, | ||
Column{ | ||
IsNullable: true, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"signed to unsigned", | ||
Column{ | ||
Type: IntegerColumnType, | ||
NumericPrecision: 4, | ||
IsUnsigned: false, | ||
}, | ||
Column{ | ||
Type: IntegerColumnType, | ||
NumericPrecision: 4, | ||
IsUnsigned: true, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"unsigned to signed", | ||
Column{ | ||
Type: IntegerColumnType, | ||
NumericPrecision: 4, | ||
IsUnsigned: true, | ||
}, | ||
Column{ | ||
Type: IntegerColumnType, | ||
NumericPrecision: 4, | ||
IsUnsigned: false, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"signed to smaller unsigned", | ||
Column{ | ||
Type: IntegerColumnType, | ||
NumericPrecision: 8, | ||
IsUnsigned: false, | ||
}, | ||
Column{ | ||
Type: IntegerColumnType, | ||
NumericPrecision: 4, | ||
IsUnsigned: true, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"same char length", | ||
Column{ | ||
CharacterMaximumLength: 20, | ||
}, | ||
Column{ | ||
CharacterMaximumLength: 20, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"reduced char length", | ||
Column{ | ||
CharacterMaximumLength: 20, | ||
}, | ||
Column{ | ||
CharacterMaximumLength: 19, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"increased char length", | ||
Column{ | ||
CharacterMaximumLength: 20, | ||
}, | ||
Column{ | ||
CharacterMaximumLength: 21, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"expand temporal", | ||
Column{ | ||
DataType: "time", | ||
}, | ||
Column{ | ||
DataType: "timestamp", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"expand temporal", | ||
Column{ | ||
DataType: "date", | ||
}, | ||
Column{ | ||
DataType: "timestamp", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"expand temporal", | ||
Column{ | ||
DataType: "date", | ||
}, | ||
Column{ | ||
DataType: "datetime", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"non expand temporal", | ||
Column{ | ||
DataType: "datetime", | ||
}, | ||
Column{ | ||
DataType: "timestamp", | ||
}, | ||
false, | ||
}, | ||
{ | ||
"expand temporal", | ||
Column{ | ||
DataType: "timestamp", | ||
}, | ||
Column{ | ||
DataType: "datetime", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"expand enum", | ||
Column{ | ||
Type: EnumColumnType, | ||
EnumValues: "'a', 'b'", | ||
}, | ||
Column{ | ||
Type: EnumColumnType, | ||
EnumValues: "'a', 'x'", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"expand enum", | ||
Column{ | ||
Type: EnumColumnType, | ||
EnumValues: "'a', 'b'", | ||
}, | ||
Column{ | ||
Type: EnumColumnType, | ||
EnumValues: "'a', 'b', 'c'", | ||
}, | ||
true, | ||
}, | ||
{ | ||
"reduce enum", | ||
Column{ | ||
Type: EnumColumnType, | ||
EnumValues: "'a', 'b', 'c'", | ||
}, | ||
Column{ | ||
Type: EnumColumnType, | ||
EnumValues: "'a', 'b'", | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
expectedExpandedColumnNames := []string{"c3"} | ||
expandedColumnNames, _ := GetExpandedColumnNames(columnsA, columnsB) | ||
assert.Equal(t, expectedExpandedColumnNames, expandedColumnNames) | ||
|
||
for _, tcase := range tcases { | ||
t.Run(tcase.name, func(t *testing.T) { | ||
expanded, _ := isExpandedColumn(&tcase.sourceCol, &tcase.targetCol) | ||
assert.Equal(t, tcase.expanded, expanded) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subsequently to the main change in this PR, it's now fine to reorder enum values, and the default
schemadiff
hints enum-reordering strategy is nowEnumReorderStrategyAllow