How to add changelog to database changes in java | Liquibase spring boot tutorial

We have many source code repositories like git and svn for managing and tracking code changes to the application developed using programming languages.

Have you ever thought of how do you manage and track and apply database schema changes? This post explains a tool called liquibase, an open-source library to track and make database changes in a single place.

Liquibase maintains and tracks changes in scripts or changelog.

This changelog is configured in XML, JSON, YAML, and SQL. Features:

  • Supports all major databases

  • database difference report generate

  • Database schema chaneglog

  • Database migrations are made with these tools

How to Integrate Liquibase in Spring Boot app?

This tutorial does not cover how to create a spring boot app.

Create a Changelog file

This .yaml contains list of change logs defined in xml or any formats liquibase/db.changelog-master.yaml:

  - include:
      file: liquibase/create-user.xml
  - include:
      file: liquibase/02-insert-users.xml

Here is an code tracking changes for table schema definition in Liquibase for creating User. liquibase/create-user.xml:

<?xml version="1.0" encoding="UTF-8"?>


  <changeSet id="01" author="Kiran">
    <createTable tableName="users"
      remarks="Table to store all user information">
      <column name="id" type="int" autoIncrement="true">
        <constraints nullable="false" unique="true" primaryKey="true"/>
      <column name="name" type="varchar(100)">
        <constraints nullable="false" unique="true"/>
        <column name="role" type="varchar(100)">
        <constraints nullable="false"/>


Here is a code tracking changes for inserting initial user data


<?xml version="1.0" encoding="UTF-8"?>


  <changeSet id="01" author="Kiran">
    <comment>user insertion data and changelog</comment>
    <insert tableName="users">
      <column name="id" valueNumeric="1"/>
      <column name="name" value="Eric"/>
      <column name="role" value="admin"/>
    <insert tableName="users">
      <column name="id" valueNumeric="2"/>
      <column name="name" value="Andrew"/>
      <column name="role" value="sales"/>
    <insert tableName="users">
      <column name="id" valueNumeric="3"/>
      <column name="name" value="John"/>
      <column name="role" value="marketing"/>
    <insert tableName="users">
      <column name="id" valueNumeric="4"/>
      <column name="name" value="Denv"/>
      <column name="role" value="admin"/>

Let’s add liquibase maven dependency into pom.xml


If you want to create an database during maven install, you can configure below settings.


If you are using the Gradle build tool, you can use below dependency

dependencies {
classpath 'org.liquibase:liquibase-core:4.4.0'
classpath "org.liquibase:liquibase-gradle-plugin:2.0.4"

We have a user table in the database which contains id, name, and role.

Once build dependencies are installed and configured, the Spring boot app automatically runs scripts in DB tracking changes.

This configure and run database schema changes at startup

How to disable liquibase at startup in Spring boot application?

Spring boot configurations are maintained in

liquibase.enabled=false or

These properties can be enabled or disabled to run liquibase at a startup. liquibase.enabled property used in Spring 4. x.x versions spring.liquibase.enabled property used for Spring 5.x.x versions Spring

difference between Liquibase and FlyWay tools

Let’s see the comparison of liquibase and flyway databases.

Liquibase and Flyway are opensource library tools and these are used as database migration tools

Compare database versions are supportedComparison of databases are not supported
Rollback database supportedRollback supported in Paid version
Changes are defined XML, SQL,JSON, and YAMlChanges are defined SQL only
Easy to manage changesIt is complex compared with Liquibase
Dashboard to track changes and viewDashboard not supported
Dry Runs like in Git are supporteddry runs are supported in Paid version