From 4007218c399f21ca23831fef26ed78fcafbe4906 Mon Sep 17 00:00:00 2001 From: sonatard Date: Mon, 17 Jun 2024 13:50:09 +0900 Subject: [PATCH 1/2] Fix NUMERIC NOT NULL --- internal/hammer/diff.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/hammer/diff.go b/internal/hammer/diff.go index 500d343..4b0608d 100644 --- a/internal/hammer/diff.go +++ b/internal/hammer/diff.go @@ -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: From 2b1a21ca076ad8d3faf52f29dacb84ed7261e22b Mon Sep 17 00:00:00 2001 From: sonatard Date: Mon, 17 Jun 2024 14:06:21 +0900 Subject: [PATCH 2/2] Add NUMERIC Type Default tests --- internal/hammer/diff_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/hammer/diff_test.go b/internal/hammer/diff_test.go index 65c36c1..bf3e057 100644 --- a/internal/hammer/diff_test.go +++ b/internal/hammer/diff_test.go @@ -119,6 +119,7 @@ CREATE TABLE t1 ( t1_8 TIMESTAMP NOT NULL, t1_9 JSON NOT NULL, t1_10 ARRAY NOT NULL, + t1_11 NUMERIC NOT NULL, ) PRIMARY KEY(t1_1); `, expected: []string{ @@ -140,6 +141,8 @@ CREATE TABLE t1 ( `ALTER TABLE t1 ALTER COLUMN t1_9 DROP DEFAULT`, `ALTER TABLE t1 ADD COLUMN t1_10 ARRAY 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`, }, }, { @@ -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 DEFAULT ([1]), + t1_11 NUMERIC DEFAULT (11), ) PRIMARY KEY(t1_1); `, expected: []string{ @@ -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 DEFAULT ([1])`, + `ALTER TABLE t1 ADD COLUMN t1_11 NUMERIC DEFAULT (11)`, }, }, { @@ -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 NOT NULL DEFAULT ([1]), + t1_11 NUMERIC NOT NULL DEFAULT (11), ) PRIMARY KEY(t1_1); `, expected: []string{ @@ -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 NOT NULL DEFAULT ([1])`, + `ALTER TABLE t1 ADD COLUMN t1_11 NUMERIC NOT NULL DEFAULT (11)`, }, }, {