-
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
schemadiff
: fix diffing of textual columns with implicit charsets
#14930
Changes from 6 commits
0db6904
d6f5b6d
c26dea1
25a070b
f2010a3
52fd91c
029ddef
6d88ce2
261c54a
5241c23
5784dc3
26acffc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,49 @@ func TestDiffTables(t *testing.T) { | |
TableQualifierHint: TableQualifierDeclared, | ||
}, | ||
}, | ||
{ | ||
name: "changing table level defaults with column specific settings, ignore charset", | ||
from: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin) default charset=latin1", | ||
to: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin)", | ||
hints: &DiffHints{ | ||
AlterTableAlgorithmStrategy: AlterTableAlgorithmStrategyCopy, | ||
TableCharsetCollateStrategy: TableCharsetCollateIgnoreAlways, | ||
}, | ||
}, | ||
{ | ||
name: "changing table level defaults with column specific settings", | ||
from: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin) default charset=latin1", | ||
to: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin)", | ||
diff: "alter table t modify column a varchar(64) character set latin1 collate latin1_bin, charset utf8mb4, algorithm = COPY", | ||
cdiff: "ALTER TABLE `t` MODIFY COLUMN `a` varchar(64) CHARACTER SET latin1 COLLATE latin1_bin, CHARSET utf8mb4, ALGORITHM = COPY", | ||
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 test expectation is wrong. In this case there should not be a 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. Agreed. Looking into it. 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. I've fixed the expected output, so that now the PR should be failing until the logic is adapted. |
||
action: "alter", | ||
fromName: "t", | ||
hints: &DiffHints{ | ||
AlterTableAlgorithmStrategy: AlterTableAlgorithmStrategyCopy, | ||
TableCharsetCollateStrategy: TableCharsetCollateStrict, | ||
}, | ||
}, | ||
{ | ||
name: "changing table level defaults with column specific settings, table already normalized", | ||
from: "create table t (a varchar(64)) default charset=latin1", | ||
to: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin)", | ||
diff: "alter table t modify column a varchar(64) character set latin1 collate latin1_bin, charset utf8mb4, algorithm = COPY", | ||
cdiff: "ALTER TABLE `t` MODIFY COLUMN `a` varchar(64) CHARACTER SET latin1 COLLATE latin1_bin, CHARSET utf8mb4, ALGORITHM = COPY", | ||
action: "alter", | ||
fromName: "t", | ||
hints: &DiffHints{ | ||
AlterTableAlgorithmStrategy: AlterTableAlgorithmStrategyCopy, | ||
TableCharsetCollateStrategy: TableCharsetCollateStrict, | ||
}, | ||
}, | ||
{ | ||
name: "changing table level charset to default", | ||
from: `create table t (i int) default charset=latin1`, | ||
to: `create table t (i int)`, | ||
action: "alter", | ||
diff: "alter table t charset utf8mb4", | ||
cdiff: "ALTER TABLE `t` CHARSET utf8mb4", | ||
}, | ||
} | ||
parser := sqlparser.NewTestParser() | ||
for _, ts := range tt { | ||
|
@@ -228,8 +271,12 @@ func TestDiffTables(t *testing.T) { | |
case ts.diff == "": | ||
assert.NoError(t, err) | ||
assert.NoError(t, dqerr) | ||
assert.Nil(t, d) | ||
assert.Nil(t, dq) | ||
if !assert.Nil(t, d) { | ||
assert.Failf(t, "found unexpected diff", "%v", d.CanonicalStatementString()) | ||
} | ||
if !assert.Nil(t, dq) { | ||
assert.Failf(t, "found unexpected diff", "%v", dq.CanonicalStatementString()) | ||
} | ||
default: | ||
assert.NoError(t, err) | ||
require.NotNil(t, d) | ||
|
@@ -357,8 +404,12 @@ func TestDiffViews(t *testing.T) { | |
case ts.diff == "": | ||
assert.NoError(t, err) | ||
assert.NoError(t, dqerr) | ||
assert.Nil(t, d) | ||
assert.Nil(t, dq) | ||
if !assert.Nil(t, d) { | ||
assert.Failf(t, "found unexpected diff", "%v", d.CanonicalStatementString()) | ||
} | ||
if !assert.Nil(t, dq) { | ||
assert.Failf(t, "found unexpected diff", "%v", dq.CanonicalStatementString()) | ||
} | ||
default: | ||
assert.NoError(t, err) | ||
require.NotNil(t, d) | ||
|
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.
I don't think this is correct. Also in this case we can get an empty / column charset due to normalization if you change the table level charset and we shouldn't then generate a diff.
This is actually visible in a broken test that was added.