$ 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);
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
After upgrading, the parsing now succeeds as shown below:
Actions Taken
go get -u cloud.google.com/go/spanner
go mod tidy