Skip to content

Latest commit

 

History

History

liquibase

PGAdapter and Liquibase

PGAdapter has Pilot Support for Liquibase. This sample shows the command line arguments and configuration that is needed in order to use Liquibase with PGAdapter.

Liquibase Requirements

  • The JDBC Connection URL must include options=-c%20spanner.ddl_transaction_mode=AutocommitExplicitTransaction. See liquibase.properties for an example URL. Cloud Spanner does not support DDL transactions, and this will ensure that DDL transactions are automatically converted to DDL batches. See DDL options for more information.
  • 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.

Running the Sample

All the steps below assume that the commands are executed from this directory.

  1. Start PGAdapter.
wget https://storage.googleapis.com/pgadapter-jar-releases/pgadapter.tar.gz && tar -xzvf pgadapter.tar.gz
java -jar pgadapter.jar -p my-project -i my-instance
  1. Manually create the databasechangeloglock and databasechangelog tables. These need to be manually created because the default table definition that is generated by Liquibase use timestamp without time zone instead of timestamp with time zone, and it would create a table without a primary key. Replace my-database with the actual name of your database.
psql -h localhost -d my-database -f create_database_change_log.sql
  1. Modify the liquibase.properties file in this directory to point to your database:
changeLogFile: dbchangelog.xml
url: jdbc:postgresql://localhost:5432/my-database?options=-c%20spanner.ddl_transaction_mode=AutocommitExplicitTransaction
  1. Update the database to according to the changes in dbchangelog.xml by executing:
mvn liquibase:update

Frequently Asked Questions

See frequently asked questions for a list of common issues and questions.

Supported Change Types

The following change types are supported by PGAdapter (see the dbchangelog.xml for examples). Note that some change types have some limitations. See limitations for a specific list.

Misc

Entities

Constraints

Data

Limitations

The Cloud Spanner PostgreSQL dialect supports a subset of the PostgreSQL DDL dialect. This means that not all change types that are supported by Liquibase for PostgreSQL can be used with Cloud Spanner.

Supported Change Types with Limitations

The following change types are supported, but with limitations:

  • createTable: The createTable change set must include a primary key constraint, and the name of the primary key constraint must be pk_<table_name>. See the examples in dbchangelog.xml.
  • createView: The create view statement must include a sql security invoker. Set fullDefinition="true" in the change set and include create view <view_name> sql security invoker as ... as thew view definition.
  • dropColumn: Only one column can be dropped per change set.
  • dropTable: Cascade constraints is not supported. All secondary indexes on the table must be dropped before the table can be dropped.
  • add*Constraint: The "disabled" and "validate" properties are not supported. Constraints are always enabled and validated.
  • addForeignKeyConstraint: The "deferrable", "initiallyDeferred", "onDelete", "onUpdate" and "validate" properties are not supported. Foreign key constraints are always validated, non-deferrable and do not support any cascading options.
  • insert, update, delete, loadData: The number of mutations may not exceed the mutation limit (https://cloud.google.com/spanner/quotas#limits_for_creating_reading_updating_and_deleting_data)

Unsupported Change Types

The following change types are not supported:

Entities

Constraints

Data