PGAdapter has Pilot Support for Liquibase version v4.12.0 and higher.
Pilot Support means that it is possible to use Liquibase
with Cloud Spanner PostgreSQL databases,
but with limitations. This means that porting an existing application from PostgreSQL to Cloud Spanner
will probably require code changes. See Limitations
in the Liquibase
sample directory for a full list of limitations.
First start PGAdapter:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
docker pull gcr.io/cloud-spanner-pg-adapter/pgadapter
docker run \
-d -p 5432:5432 \
-v ${GOOGLE_APPLICATION_CREDENTIALS}:${GOOGLE_APPLICATION_CREDENTIALS}:ro \
-e GOOGLE_APPLICATION_CREDENTIALS \
gcr.io/cloud-spanner-pg-adapter/pgadapter \
-p my-project -i my-instance \
-x
The databasechangeloglock
and databasechangelog
tables must be created manually, as the
DDL script that is automatically generated by Liquibase will try to use the data type
timestamp without time zone
, which is not supported by Cloud Spanner. The DDL script to create
these tables manually can be found in create_database_change_log.sql.
Liquibase will by default use DDL transactions when connecting to PostgreSQL databases. This is not supported by Cloud Spanner. Instead, PGAdapter can automatically convert DDL transactions into DDL batches. This requires the following option to be set in the JDBC connection URL:
url: jdbc:postgresql://localhost:5432/liquibase-test?options=-c%20spanner.ddl_transaction_mode=AutocommitExplicitTransaction
See liquibase.properties for an example connection URL.
Run Liquibase using for example the Maven plugin:
mvn liquibase:validate
This directory contains a full sample of how to work with Liquibase
with
Cloud Spanner and PGAdapter. The sample readme file also lists the current limitations
when working with Liquibase
.