Liquibase – versional control for database

As a Java developer dealing with databases i knew about hibernate and ORM tool to connect project with databases using simple xml configuration files. I though liquibase would be something similar, since had a rough idea that I stores the database table structure (rather script) in an Xml file. But to my surprise it is entirely different.


Problems to address related to databases especially in Agile development

# I have taken the new code on my sand box but functionality is not working, I think there are some database related changes.

–        Conventional solution: I picked the latest database script and run it on mysql database and functionality started working well.

–        Liquibase solution : As i run the mvn install after code synchronization, the database also got synchronized to current version.


# I found some changes in the database but I do not know who has made those changes and when.

–        Conventional solution I emailed the entire dev group and waited till some came up with the owner ship of that change.

–        Liquibase solution I just referred the author name for the change set and pinged him to discuss without sending any junk mails.

# I have reverted my code to a particular tag or release point, but I am not aware about the database status at that point of time.

–        Conventional solution I searched the database logs and scripts with date stamp and after a struggle I found the script to run.

–        Liquibase solution I used Liquibase tag to generate database base to a particular time line.

# I have to change the database from mysql to oracle or derby.

–        Conventional solution A new script is required for the new database

–        Liquibase solution Same xml with minor modification could be used to accommodate any database changes.


There are few problems which are common especially in agile development where database keeps on changes every now and that. To address all these problem especially for developers a new tool called as Liquibase is developed. It is integrated seamlessly in the codebase, which can be controlled using any conventional versioning tool. Hence like the project code changes, you can also maintain the database changes related to code changes in your work space and modify it.


What is Liquibase ?

As we have versioning tool for our code so that we can maintain different tags to roll back and maintain the incremental evolution/history of our code. Similarly, now that database changes can be tracked with timestamp, id, author and tag. Instead of making direct changes to database the changes are done through liquibase Databasechangelog xml file example “database_mods.xml”.

The advantage of using this is, it become a single entry point to make changes in database, easier to track, and roll back to a restore point for a particular release of project. You will get to know how has made what all changes and when.

In short:

LiquiBase is an open source database-independent library for tracking, managing and applying database changes. In laymen terms it is more like a database script in xml format. However it have its own IDE, plugins for eclipse and perform several other important activities.


Two important table of liquibase:

“databasechangeloglock ” is used to control the concurrency while updating the database. For example if more that 2 developers makes changes to database table instance at the same time, one developer acquires the lock so prevent the inconsistency.


“Databasechangelog” is the  change log table in which all the changes set with their description, author, timestamp, ids and other properties gets stored.

How do we run liquibase, mvn – so when we build we used to run it before the compilation.


Restore point :

To get to a particular restore point of database one can use any of the below :

1.      Roll back to a particular tag.

2.      Roll back to a particular date.

3.      Roll back to a particular count.


Database Diff:

Before final release you want to make sure that databases are in sync you use Diff tool for databases for the same by following methods:

1.      Generate a report

2.      xml change log block and compare it later.


Sample liquibase xml file:


<?xml version=”1.0″ encoding=”UTF-8″?>

<databaseChangeLog xmlns=”;




<changeSet id=”153-mysql” author=”ajain” dbms=”mysql”>

<comment> adding a new table for roles  </comment>

<createTable tableName=”fusion_role”>

<column name=”role_id” type=”bigint”>

<constraints primaryKey=”true” nullable=”false”/>


<column name=”description” type=”varchar(255)” />

<column name=”name” type=”varchar(255)”/>

<column name=”version” type=”integer”/>

<column name=”organization_id” type=”bigint” />


<addAutoIncrement tableName=”fusion_role” columnName=”role_id” columnDataType=”bigint”/>





Video presentation to know liquibase more :

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.