daichirata / hammer

🛠 hammer is a command-line tool to schema management for Google Cloud Spanner.
MIT License
83 stars 24 forks source link

Cannot add NOT NULL column on Numeric Type #59

Closed sonatard closed 5 months ago

sonatard commented 5 months ago

Adding a NOT NULL Numeric type to the schema and applying it with Hammer results in an error.

CREATE TABLE Test (
   ID STRING(MAX) NOT NULL,
+   A NUMERIC NOT NULL,
) PRIMARY KEY(ID);
$ hammer apply spanner://projects/xxx/instances/yyy/databases/zzz schema.sql
Error: rpc error: code = Unimplemented desc = Cannot add NOT NULL column Test.A to existing table Test.
exit status 1

$ hammer diff spanner://projects/xxx/instances/yyy/databases/zzz ./ddl/schema.sql
ALTER TABLE Test ADD COLUMN A NUMERIC NOT NULL;
ALTER TABLE Test ALTER COLUMN A DROP DEFAULT;

Hammer does not support default values for the Numeric type.

I am expecting the following results.

$ hammer diff spanner://projects/xxx/instances/yyy/databases/zzz ./ddl/schema.sql
ALTER TABLE Test ADD COLUMN A NUMERIC NOT NULL DEFAULT (0);
ALTER TABLE Test ALTER COLUMN A DROP DEFAULT;