-
Notifications
You must be signed in to change notification settings - Fork 24
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
fix timestamp with default values comparison #54
fix timestamp with default values comparison #54
Conversation
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.
@reedom Thank you sincerely for the bug report! I have left some comments, please check them out.
internal/hammer/diff.go
Outdated
@@ -611,7 +611,7 @@ func (g *Generator) primaryKeyEqual(x, y *Table) bool { | |||
} | |||
|
|||
func (g *Generator) columnDefEqual(x, y spansql.ColumnDef) bool { | |||
return cmp.Equal(x, y, cmpopts.IgnoreTypes(spansql.Position{})) | |||
return cmp.Equal(x, y, cmpopts.IgnoreTypes(spansql.Position{}), cmpopts.IgnoreUnexported(spansql.TimestampLiteral{})) |
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.
If I ignore changes here, won't changes to the default value be ignored?
I thought the code would be much better if it could be changed to pass the following test cases.
from: `
CREATE TABLE Nonces (
nonce INT64 NOT NULL,
expires TIMESTAMP NOT NULL DEFAULT(TIMESTAMP '2000-01-01 00:00:00.000000+00:00'),
) PRIMARY KEY(nonce);
`,
to: `
CREATE TABLE Nonces (
nonce INT64 NOT NULL,
expires TIMESTAMP NOT NULL DEFAULT(TIMESTAMP '2000-01-01 12:00:00.000000+00:00'),
) PRIMARY KEY(nonce);
`,
ignoreAlterDatabase: true,
expected: []string{
`ALTER TABLE Nonces ALTER COLUMN expires TIMESTAMP NOT NULL DEFAULT (TIMESTAMP '2000-01-01 12:00:00.000000+00:00')`,
},
This is an example of an approach, but you might want to make the following comparison here and modify it so that subsequent code will issue an alter statement for changes in the default value.
cmp.Comparer(func(x, y spansql.TimestampLiteral) bool {
return time.Time(x).Equal(time.Time(y))
}))
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.
My bad…
Ok, I've improved the code.
Could you check it again?
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.
Sorry, it seems I had rerun only a failed test at that time. 🙇
Now the test runs in success locally.
Thank you for fixing the problem! I appreciate your contribution. |
If both sides have identical columns of timestamp with a default value,
it panics:
test that reproduces:
https://github.com/murasaki-bv/hammer/blob/f8af0e9e7cd4b06716aee0fdffe46c21db6aa690/internal/hammer/diff_test.go#L1364-L1381