cloudspannerecosystem / spanner-schema-diff-tool

Compare two Cloud Spanner Schema (DDL) files, determine the differences and generate the required ALTER statements to convert one schema to the other.
Apache License 2.0
33 stars 17 forks source link

Support for alter database statement #10

Closed fujin closed 1 year ago

fujin commented 2 years ago

I have an empty Spanner database (created with Terraform) which, during creation, is creating a DDL like this:

ALTER DATABASE test SET OPTIONS (
  version_retention_period = '7d'
);

When I run the diff tool, I get an error here:

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported statement type: alter_database_statement
    at com.google.cloud.solutions.spannerddl.diff.DdlDiff.separateTablesIndexesConstraints(DdlDiff.java:539)
    at com.google.cloud.solutions.spannerddl.diff.DdlDiff.build(DdlDiff.java:483)
    at com.google.cloud.solutions.spannerddl.diff.DdlDiff.main(DdlDiff.java:638)

As far as I can tell, the tool doesn't allow for a non-default version_retention_period to be set via ALTER DATABASE, as it cannot parse the ALTER DATABASE statement.

We have two potential workarounds and wanted to know your input:

zhiwei-arbo commented 1 year ago

jfyi for anyone looking at this, in my own fork I made it a no-op here (warn instead of throw)

It also seems possible to parse it by creating the relevant ASTXXX files, but I don't have such a use case yet