daichirata / hammer

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

update cloud.google.com/go/spanner to v1.62.0 #58

Closed nametake closed 6 months ago

nametake commented 6 months ago

Updated the version of cloud.google.com/go/spanner to v1.62.0.

And, fixed the test cases that were failing due to this update.

Reason

There was an issue with parsing the syntax for foreign key actions in spansql.

Reference: Cloud Spanner Foreign Key Actions

$ cat ./old.sql
CREATE TABLE Artist (
  ID STRING(MAX) NOT NULL,
  Name STRING(MAX) NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true),
) PRIMARY KEY(ID);

CREATE TABLE Album (
  ID STRING(MAX) NOT NULL,
  Title STRING(MAX) NOT NULL,
  ArtistID STRING(MAX) NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true),
  FOREIGN KEY (Artist) REFERENCES Artist (ID) ON DELETE NO ACTION,
) PRIMARY KEY(ID);
$ cat ./new.sql
CREATE TABLE Artist (
  ID STRING(MAX) NOT NULL,
  Name STRING(MAX) NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true),
) PRIMARY KEY(ID);

CREATE TABLE Album (
  ID STRING(MAX) NOT NULL,
  Title STRING(MAX) NOT NULL,
  ArtistID STRING(MAX) NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true),
  FOREIGN KEY (Artist) REFERENCES Artist (ID) ON DELETE NO ACTION,
) PRIMARY KEY(ID);

CREATE TABLE Song (
  ID STRING(MAX) NOT NULL,
  Title STRING(MAX) NOT NULL,
  AlbumID STRING(MAX) NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true),
) PRIMARY KEY(ID);
$ go run main.go diff ./old.sql ./new.sql
Error: ./old.sql failed to parse ddl: ./old.sql:12: got "ON", want ")" or ","
exit status 1

After upgrading, the parsing now succeeds as shown below:

$ go run main.go diff ./old.sql ./new.sql
CREATE TABLE Song (
  ID STRING(MAX) NOT NULL,
  Title STRING(MAX) NOT NULL,
  AlbumID STRING(MAX) NOT NULL,
  CreatedAt TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true),
) PRIMARY KEY(ID);

Actions Taken

daichirata commented 6 months ago

Thank you!