Skip to content

Commit

Permalink
Merge pull request #60 from sonatard/numeric
Browse files Browse the repository at this point in the history
Fix NUMERIC NOT NULL
  • Loading branch information
daichirata authored Jun 18, 2024
2 parents 7cc6a2c + 2b1a21c commit fb333c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/hammer/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ func (g *Generator) setDefault(col spansql.ColumnDef) spansql.ColumnDef {
col.Default = spansql.IntegerLiteral(0)
case spansql.Float64:
col.Default = spansql.FloatLiteral(0)
case spansql.Numeric:
col.Default = spansql.FloatLiteral(0)
case spansql.String:
col.Default = spansql.StringLiteral("")
case spansql.Bytes:
Expand Down
7 changes: 7 additions & 0 deletions internal/hammer/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ CREATE TABLE t1 (
t1_8 TIMESTAMP NOT NULL,
t1_9 JSON NOT NULL,
t1_10 ARRAY<INT64> NOT NULL,
t1_11 NUMERIC NOT NULL,
) PRIMARY KEY(t1_1);
`,
expected: []string{
Expand All @@ -140,6 +141,8 @@ CREATE TABLE t1 (
`ALTER TABLE t1 ALTER COLUMN t1_9 DROP DEFAULT`,
`ALTER TABLE t1 ADD COLUMN t1_10 ARRAY<INT64> NOT NULL DEFAULT ([])`,
`ALTER TABLE t1 ALTER COLUMN t1_10 DROP DEFAULT`,
`ALTER TABLE t1 ADD COLUMN t1_11 NUMERIC NOT NULL DEFAULT (0)`,
`ALTER TABLE t1 ALTER COLUMN t1_11 DROP DEFAULT`,
},
},
{
Expand All @@ -161,6 +164,7 @@ CREATE TABLE t1 (
t1_8 TIMESTAMP DEFAULT (TIMESTAMP '2022-06-18 04:36:00.000000+09:00'),
t1_9 JSON DEFAULT (JSON '{"key": "value"}'),
t1_10 ARRAY<INT64> DEFAULT ([1]),
t1_11 NUMERIC DEFAULT (11),
) PRIMARY KEY(t1_1);
`,
expected: []string{
Expand All @@ -173,6 +177,7 @@ CREATE TABLE t1 (
`ALTER TABLE t1 ADD COLUMN t1_8 TIMESTAMP DEFAULT (TIMESTAMP '2022-06-18 04:36:00.000000+09:00')`,
`ALTER TABLE t1 ADD COLUMN t1_9 JSON DEFAULT (JSON '{"key": "value"}')`,
`ALTER TABLE t1 ADD COLUMN t1_10 ARRAY<INT64> DEFAULT ([1])`,
`ALTER TABLE t1 ADD COLUMN t1_11 NUMERIC DEFAULT (11)`,
},
},
{
Expand All @@ -194,6 +199,7 @@ CREATE TABLE t1 (
t1_8 TIMESTAMP NOT NULL DEFAULT (TIMESTAMP '2022-06-18 04:36:00.000000+09:00'),
t1_9 JSON NOT NULL DEFAULT (JSON '{"key": "value"}'),
t1_10 ARRAY<INT64> NOT NULL DEFAULT ([1]),
t1_11 NUMERIC NOT NULL DEFAULT (11),
) PRIMARY KEY(t1_1);
`,
expected: []string{
Expand All @@ -206,6 +212,7 @@ CREATE TABLE t1 (
`ALTER TABLE t1 ADD COLUMN t1_8 TIMESTAMP NOT NULL DEFAULT (TIMESTAMP '2022-06-18 04:36:00.000000+09:00')`,
`ALTER TABLE t1 ADD COLUMN t1_9 JSON NOT NULL DEFAULT (JSON '{"key": "value"}')`,
`ALTER TABLE t1 ADD COLUMN t1_10 ARRAY<INT64> NOT NULL DEFAULT ([1])`,
`ALTER TABLE t1 ADD COLUMN t1_11 NUMERIC NOT NULL DEFAULT (11)`,
},
},
{
Expand Down

0 comments on commit fb333c3

Please sign in to comment.