What is Liquibase
Liquibase is an open-source database-independent library for tracking, managing, and applying database schema changes. Basically, it works with various types of databases and supports various file formats for defining the database structure. The feature that is probably most useful in Liquibase is its ability to roll changes back and forward from a specific point and save you from needing to know what was the last change you ran on a specific database instance.
Integration with Spring Boot
Liquibase is a Java-based tool integrated with Maven and Spring Boot and now we need to create a spring boot project using Spring Initializr.
Add Mysql configuration in application.properties
After the configuration in the project structure under src/main/resources, we will see that we have a package with the name db and inside there is another package with the name changelog, Now we will add all changelogs.
Here, we need to create the changelog master file as db/changelog-master.xml and it will track all changes.
This is the content of the file:
Now, Let’s make our first migration in which we will create a new table name as a student which will have id, first name, and last name.
Create a file in db/changelog and name it db-changelog-create_student_table-1.0.sql.
That’s it, now let’s run the application.
If we inspect the database changelog table and we will see our first migration as follow :
We learned how easy and useful Spring Boot Liquibase is. When you are starting a new project this is a database versioning tool that will help in managing the database schema and speed up the productivity of the team and if we have an old project we can still integrate it easily. So, This blog provided details on how to use Liquibase in the Spring Boot application.