Liquibase

Poonam Sharma
2 min readNov 20, 2020

Liquibase is an open source version control tool for database schema migration. In simple words, its a plugin to manage the versions for the database schema

It keeps the logs of the changes made on the database schema. It could be of great help for developers who want to maintain their changes made to DB.

Liquibase uses Change Log file as a configuration guidelines to make changes to the underlying database schema in order. The changesets files supports XML, JSON, YAML, and SQL formats.

It creates its own two tables for maintaining version and lock i.e DATABASECHANGELOG and DATABASECHANGELOGLOCK

DATABASECHANGELOG: to track which changesets have been run

DATABASECHANGELOGLOCK: to provide lock for the table on which changes are being made to ensure only single instance of Liquibase is running at a time.

Following are the Steps to add Liquibase in a simple Spring boot application :

1. Add liquibase dependency in maven pom.xml

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>

2. Add parameters in application.properties. Default path is db/changelog/db.changelogmaster.yml

spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml

3. Create master databasechangelog xml file and other specific changeset file. Include these changeset files in the master file.

One thing to note is if we want to use spring-data-jpa along with Liquibase then following thing needs to be added in the application. properties. Update allows JPA to make changes on the table without modifying the already available constraints. Else if we don’t add this our DDL query wont be applied to table with liquibase

Changeset should never be used to apply index to table as indexing consumes a large amount of time and liquibase keeps the lock of the table and doesnot allow any other process to run for that period of time.

--

--