Liquibase tracks, manages and applies database changes — table structures as well as data — around three ideas: version numbers, comparisons, and rollbacks. There is no official Liquibase adapter for gbase, but the mysql driver works. This post walks through managing schema changes on a China-domestically developed GBase 8a 9.5.3 cluster from GBASE.

Core concepts

  • Multiple authors are supported. Each change has an ID that, together with the author, forms a unique identifier; once update has run, the contents of that change must not be edited.
  • Changes can be rolled back, and tags allow a whole-set rollback. A changelog file can be edited repeatedly and only the new parts take effect.
  • ChangeSets contain Change Types (add a column, add a primary key, ...) while context, label and precondition control when and where a change is deployed. Both SQL and XML forms are available:
-- changeset liquibaseuser:1 create table Details1 ( id int primary key, name varchar(255) ); -- rollback drop table Details1; 
<changeSet author="liquibase" id="30"> <createTable tableName="table30"> <column name="id" type="int"/> <column name="heading" type="varchar(36)"/> <column name="author" type="varchar(36)"/> </createTable> <rollback> drop table table30 </rollback> </changeSet> 
  • ChangeLog: SQL, XML, JSON or YAML files listing changesets in order. Author plus sequence number must be unique within a file, otherwise changesets had duplicate identifiers. Editing an already-applied change triggers a checksum failure:
Validation Failed: 1 changesets check sum gbase.sql::1::XXX was: 9:70253bd57ffa0fa6faf0b0c0103ab76a but is now: 9:e602d9babfc3872b65daa05bd5c9c97e 
  • properties file: database connection details and parameters that rarely change.
  • Commands: update, rollback, snapshot, diff, status and utility commands.
  • Two tracking tables: DATABASECHANGELOG records deployed changes; DATABASECHANGELOGLOCK stops two Liquibase instances from updating the same database at once.
  • Interfaces: CLI, flow files (Pro), Maven, Spring Boot, Java API — the CLI is the simplest. The parameters you almost always need are --changelog-file, --url, --username, --password.

Installing Liquibase

On Red Hat / CentOS, as root:

rpm --import https://repo.liquibase.com/liquibase.asc yum install -y yum-utils yum-config-manager --add-repo https://repo.liquibase.com/repo-liquibase-com.repo yum install liquibase 

This installs liquibase 4.30.0-1 (153 MB download, 169 MB installed) on Java 1.8.0_291:

Starting Liquibase at 10:26:27 using Java 1.8.0_291 (version 4.30.0 #4943 built at 2024-10-31 17:00+0000) Liquibase Version: 4.30.0 

Creating the project

mkdir liquibasegbase && cd liquibasegbase/ liquibase init project-new 

Accepting the defaults generates example-changelog.sql, liquibase.properties, and a set of flow and checks files such as liquibase.flowfile.yaml and liquibase.checks-package.yaml.

Editing the properties file

Point it at the cluster with the mysql driver on port 5258:

liquibase.command.url=jdbc:mysql://10.0.2.103:5258/liquibase liquibase.command.username: root liquibase.command.password: XXXXXXX 

Applying changes

The bundled example

liquibase update 

Three changesets run and UPDATE SUMMARY reports Run: 3. Logging into the gbase client (9.5.3.28.18.r1_patch.3b726d68), show databases; now lists liquibase, and show tables; inside it shows company, person, plus the two tracking tables:

+-----------------------+ | Tables_in_liquibase | +-----------------------+ | company | | databasechangelog | | databasechangeloglock | | person | +-----------------------+ 4 rows in set (Elapsed: 00:00:00.00) 

Adding a GBase distributed table

Switch the default SQL file to gbase.sql and write a distributed by('id') table. The labels and contexts below are Chinese for "create distributed table" and "create int-typed distributed table":

--liquibase formatted sql --changeset XXX:1 labels:建分布表 context:建数字int类型的分布表 --comment: example comment create table gbase ( id int, name varchar(50) )distributed by('id') --rollback DROP TABLE gbase; 

After liquibase update (Run: 1), show tables; includes gbase.

Several changes at once

Changesets with an existing label are not re-applied; only new ones run. That suits a changelog file edited multiple times. Here one distributed table and one replicated table are added together:

--liquibase formatted sql --changeset XXX:2 labels:建分布表2 context:建数字int类型的分布表2 --comment: 分布表2 create table gbase2 ( id int, name varchar(50) )distributed by('id') --rollback DROP TABLE gbase2; --changeset XXX:3 labels:建复制表1 context:建复制表1 --comment: 复制表1 create table gbaserep ( id int, name varchar(50) )replicated --rollback DROP TABLE gbaserep; 

distributed by('id') and replicated are the two data distribution styles in GBase 8a.

Tag

liquibase tag 'test000' 

The tag is written to the TAG column of databasechangelog and can be queried with plain SQL:

Successfully tagged 'root@10.0.2.103@jdbc:mysql://10.0.2.103:5258/liquibase' 

Rollback

Run update once more to create gbase2, tag it test001, then roll back to the previous tag:

liquibase rollback 'test000' 
Rolling Back Changeset: gbase.sql::2::XXX Liquibase command 'rollback' was executed successfully. 

gbase2 disappears from show tables;, and select * from databasechangelog; drops from 5 rows back to 4 — rollback really operates at changeset granularity.

Command-line parameters

liquibase --help lists every Global Option and command. Day-to-day commands include update, update-sql, rollback, rollback-count, tag, status, snapshot, diff and release-locks; concurrency-related globals include --changelog-lock-poll-rate (default 10 seconds), --changelog-lock-wait-time-in-minutes (default 5 minutes) and --changelog-parse-mode (default STRICT).

Going forward, the useful part is that no vendor-specific plugin is required: with the mysql driver and port 5258, Liquibase talks to a gbase cluster, and GBase-specific DDL such as distributed and replicated tables goes straight into a formatted SQL changelog. update, tag and rollback all work end to end, which gives the database a traceable, reversible history of schema changes instead of a folder of ad-hoc scripts.