GCP – Managing schema changes on Cloud Spanner using Liquibase
We’re very happy to announce that you can now use Liquibase’s open-source database devops library to manage and automate schema changes in Cloud Spanner. The availability of Liquibase Cloud Spanner extension beta version 1.0 brings all of Liquibase’s CI/CD benefits to Spanner.
You can find the source and detailed information in GitHub here: cloudspannerecosystem/liquibase-spanner
Supported Features
The following change types are supported by the extension: createTable, dropTable, addColumn, modifyDataType, addNotNullConstraint, dropColumn, createIndex, dropIndex, addForeignKeyConstraint, dropForeignKeyConstraint, dropAllForeignKeyConstraints, addLookupTable, insert, update, loadData, and loadUpdateData.
ChangeTypes are all tested as unit tests, with the Spanner emulator, and with a real Spanner.
Example
An example changelog.yaml is provided that demonstrates a changelog applied to Spanner. This is to help apply Liquibase Best Practices using Spanner.
It includes the following:
-
create-schema.yaml: Create for Singers and Albums tables, including interleaved tables, column options, and indexes.
-
load-data-singers.yaml: Load data into Singers table from CSV.
-
load-update-data-singers.yaml: Insert/update Singers table from CSV.
-
add-lookup-table-singers-countries.yaml: Create Countries table as a foreign key from Country field in Singers.
-
modify-data-type-singers-lastname.yaml: Alter datatype in Singers LastName column.
-
insert.yaml: Insert rows into Singers table.
-
delete.yaml: Delete rows from Singers.
-
update.yaml: Update rows in Singers.
To get started, create a Cloud Spanner instance in your GCP account or in a Spanner Qwiklab and try the Liquibase extension
Read More for the details.