diff --git a/internal/hammer/diff.go b/internal/hammer/diff.go index d873cb3..9a55f71 100644 --- a/internal/hammer/diff.go +++ b/internal/hammer/diff.go @@ -403,7 +403,7 @@ func (g *Generator) generateDDLForColumns(from, to *Table) DDL { if g.columnTypeEqual(fromCol, toCol) && fromCol.Generated == nil && toCol.Generated == nil { if fromCol.Type.Base == spansql.Timestamp { - if fromCol.NotNull != toCol.NotNull { + if fromCol.NotNull != toCol.NotNull || !reflect.DeepEqual(fromCol.Default, toCol.Default) { if !fromCol.NotNull && toCol.NotNull { ddl.Append(Update{Table: to.Name, Def: toCol}) } @@ -611,7 +611,12 @@ 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{}), + cmp.Comparer(func(x, y spansql.TimestampLiteral) bool { + return time.Time(x).Equal(time.Time(y)) + }), + ) } func (g *Generator) columnTypeEqual(x, y spansql.ColumnDef) bool { diff --git a/internal/hammer/diff_test.go b/internal/hammer/diff_test.go index 55ad7b2..f36a9f5 100644 --- a/internal/hammer/diff_test.go +++ b/internal/hammer/diff_test.go @@ -1361,6 +1361,25 @@ CREATE CHANGE STREAM SomeStream FOR ALL; ignoreAlterDatabase: true, expected: []string{"ALTER CHANGE STREAM SomeStream SET OPTIONS (retention_period='1d', value_capture_type='OLD_AND_NEW_VALUES')"}, }, + { + name: "both sides have identical fields of timestamp with a default value", + 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')`, + }, + }, } for _, v := range values { t.Run(v.name, func(t *testing.T) {