MariaDB TX, proven in production and driven by the community, is a complete database solution for any and every enterprise — a modern database for modern applications.

One major system development problem has always been how and when we update the database. There are always at least a few questions that crop up:

Were scripts for DB changes created?

Where do we save the DB changes?

When should we apply these changes?

Have these changes already been implemented?

How do we track and manage database changes?

Who made these changes?

Liquibase is a library that can help address these issues. Liquibase is an open source database used to track, manage, and apply changes to the database.

Liquibase works better because it understands what the changes are. For example, a database comparison program would simply see the “person” table on integration has a “firstname” and a “lastname” column, but on live, the “person” table has a “name” column. It would report that you need to drop the “name” column and add a “firstname” and a “lastname” column. While this would leave you with the correct schema, you would lose everyone’s name in the process. With Liquibase, you would have a changeset that says “rename ‘name’ to ‘lastname’ and add a ‘firstname’ column” or, even better, “split the name column on a space and place the values in new ‘firstname’ and ‘lastname’ columns, then drop the ‘name’ column.” Knowing why they are different allows changes to production databases without the fear of losing valuable data.

In this post, I will show how you can use the powerful tool Liquibase together with Gradle to automate these tasks, from there will be easy to put Liquibase to work with your continuos integration tools.

Some important concepts:

Changelog File

The changelog is the file that contains references of all the scripts that should be applied to the database in any environment.

ChangeSet Files

ChangeSet files:

Are all the files recorded in a changelog.

Can be written primarily in XML, YAML, JSON, and SQL, which I chose for this example.

Some advice:

IDs cannot be repeated. Otherwise, they will not run.

Scripts should be small.

Rollbacks should be added whenever possible.

Must be added new scripts on the changelog.xml

Everything that was executed is registered on the table DATABASECHANGELOG