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

We utlized source code repositories like git and svn to manage and track code changes in applications developed using various programming languages. Have you ever pondered how to manage, track, and implement database schema changes?

This post introduces a tool called Liquibase, an open-source library designed to track and implement database changes from a centralized single place.

Liquibase effectively maintains and tracks changes through scripts or a changelog. This changelog can be configured in XML, JSON, YAML, or SQL.


  • Supports all major databases.
  • Generates database difference reports.
  • Manages database schema changelogs.
  • Facilitates database migrations through these tools.

How to Integrate Liquibase in a Spring Boot App?

This tutorial assumes you already have a Spring Boot application set up.

Create a Changelog file

Create a .yaml file containing a list of change logs defined in XML or any other format.

Here’s an example of liquibase/db.changelog-master.yaml:

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

Below is the code tracking changes for the table schema definition in Liquibase for creating a User


<?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"/>


And here is the 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"/>

Now, let’s add Liquibase Maven dependency into pom.xml:


To create a database during Maven install, configure the following settings:


For Gradle build tool users, use the following dependency:

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

Assuming you have a user table in the database with id, name, and role columns,Once build dependencies are installed and configured, the Spring boot app allows Liquibase will automatically run the scripts tracking changes in the database at startup.

This configure and run database schema changes at startup

How to Disable Liquibase at Startup in a Spring Boot Application?

In, you can control Liquibase startup behavior.


These properties can be enabled or disabled to run Liquibase at startup. liquibase.enabled is used in Spring 4.x.x versions, while spring.liquibase.enabled is used for Spring 5.x.x versions.

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 These are the key differences between Liquibase and Flyway

Supports comparing database versionsDoes not support comparing databases
Supports rollback database changesRollback is supported in the paid version
Allows changes defined in XML, SQL, JSON, YAMLChanges are defined in SQL only
Easy to manage changesRelatively complex compared to Liquibase
Provides a dashboard to track changes and viewsDoes not support a dashboard
Supports dry runs similar to GitDry runs are supported in the paid version