Liquibase: A Tool for Database Management
Introduction
Liquibase is a unique tool that revolutionizes the way databases are managed in the world of programming. As an open-source software, Liquibase offers developers powerful capabilities for tracking, managing, and deploying changes in databases in a controlled and efficient manner. In today’s dynamically changing technological environment, where speed and accuracy are crucial, Liquibase becomes an invaluable tool for programming teams around the world.
The beginnings of Liquibase date back to 2006, when it was created by Nathan Voxland. Since then, this tool has evolved, becoming one of the most trusted and widely used solutions in the field of database management. With its ability to handle multiple platforms and databases, Liquibase provides unmatched flexibility and compatibility, making it an ideal choice for various projects and organizations.
One of the main advantages of Liquibase is its text-file-based approach to tracking database changes. This approach allows for easy tracking of change history, team collaboration, and integration with version control systems, such as Git. As a result, Liquibase not only facilitates database management but also supports best practices in DevOps and Continuous Integration/Continuous Deployment (CI/CD).
In this article, we will take a closer look at the functionalities of Liquibase, examining how this tool changes the rules of the game in database management. We will discuss its key features, such as change file formats, version control mechanisms, and support for various database systems. Additionally, I will present a usage example, demonstrating how Liquibase can be used to improve efficiency and accuracy in managing database changes.
Key Features of Liquibase:
- Change File Formats: Liquibase allows defining database changes in various file formats, including XML, YAML, JSON, and SQL. This enables users to choose the format that best fits their project and skills.
- Platform Independence: It operates on various operating systems and is compatible with many database management systems, making it a universal tool.
- Change Tracking: Liquibase tracks database changes in a controlled manner, providing a complete history and audit of changes.
- CI/CD Tool Integration: Easily integrates with popular Continuous Integration and Continuous Deployment tools, such as Jenkins, Bamboo, or TeamCity.
- Rollbacks: The ability to easily revert changes (rollbacks) in the database, which is crucial in the event of errors or the need to restore previous states.
- Community Support and Extensibility: With a wide user and developer community, Liquibase is continuously developed and adapted to new needs.
- Version Control: Database changes can be versioned, allowing for better organization and control over the development process.
Advantages of Liquibase:
- Facilitates Change Management: Enables easy management, tracking, and deployment of changes in database schemas, which is key in dynamic software development environments.
- Improves Collaboration: Facilitates teamwork through the use of standard file formats and integration with version control tools.
- Increases Efficiency: The Automation of processes related to database changes significantly increases the efficiency of development teams.
- Reduces Error Risk: Automatic change tracking and the ability to test changes before deploying minimizes the risk of errors.
- Flexibility: The ability to adapt to different environments and project needs.
- Support for Multiple Databases: The ability to work with various database systems increases the tool’s universality. Supported databases
Installation and Configuration
To start using Liquibase, you need to download the appropriate version from the project’s website.
After a successful installation, you should be able to execute the following command in your console:

If everything has been installed correctly, you should see the details of your installation.
Now, to create some database structure, you can prepare files with instructions. As mentioned earlier, these files can be prepared in SQL, XML, YAML, or JSON formats. In my example, I will use YAML files.
For the purposes of this presentation, I have created 4 files, one containing the instruction to create two tables, another adding an index and a column, and the instruction about which files should be executed:

File :001_table_creation.yaml
As we can see, the yaml file contains the definition of each column and table, in a very readable form. I added also tags for easier navigation, denoting the version of our database. We also have here a defined action in case of errors under Preconditions. At the very end, as a matter of good practice, there is a rollback section defined, which is an instruction on how to undo changes made in a given file.
File: 002_addIndex.yaml
File: 003_addColumn.yaml
And also the master.yaml file where there are instructions on what files and in what order should be applied, to create the desired data structure.
Working with Liquibase
Below, I will try to present some of the most important commands that allow you to start working with this tool. A full list of commands can be found in the documentation, which contains many detailed pieces of information about their use.
Using the command:
We can create a default h2 base configuration
Now with the command:
We will start the H2 database, after which its console should open. Then, going to the location of my files, I can execute the command:
The command listed the SQL commands for verification that will be fired at the update operation. So we can verify if there is definitely nothing there that we would not want to execute. Before performing the update operation, we can also perform the validate operation, which can detect potential problems.
And as you can see below, none of the potential bugs were detected.
So using the update command will apply our changes.
As you can see, our tables have been created

In addition to our ADDRESS and COMPANIES tables, we have created auxiliary tables Liquibase DATABASECHANGELOGLOCK, where database lock information is stored, and DATABASECHANGELOG containing the history of changes:

We can also check with the status command whether our database is up to date with the file:
Now let’s assume that the last change made caused problems and we want to undo the addition of the ‘TaxNumber’ column, which, as we see is present in the structure:

To do this, I will run a command that will roll back the database to a specific version.
Which, as we see below, modified our changelog, and also the column added in version 1.0.3 is already absent.

I have presented here a really simple case of the rollback of changes. However, Liquibase is a very powerful tool and the purpose of this article is to briefly introduce it, which I hope will encourage you to delve further into its capabilities. Therefore, I recommend that you take a look at the various options in the documentation, as it can be a tool worth implementing in many projects.
Spring-boot integration
Liquibase can also be attached as a dependency to our project and integrated into our application using SpringBoot.
To demonstrate this I will also use a simple H2 base here and initialize the project using Spring Initalizr

If we just want to add a dependency to the pom:
Then, in my application.yaml in addition to the H2 base configuration, it points to the liquibase.change-log property, specifying the locations, of my master.yaml file
With this configuration, liquibase will initialize the data structure at the moment of the application startup as you can see in the following log.
Summary
To sum up, Liquibase is a revolutionary tool in the world of database management, offering a solution for efficient, controlled, and automated implementation of changes in databases. Its universality, evident in support for various change file formats, as well as platform independence and database solutions, makes it indispensable in diverse development environments.
Key features of Liquibase, such as integration with CI/CD tools, the ability to roll back changes, and community support, make this tool not only versatile but also flexible, adapting to the changing needs and challenges of contemporary programming. By facilitating collaboration between teams and improving efficiency and accuracy in change management, Liquibase significantly contributes to increasing productivity and minimizing the risk of errors in projects.
In this article, we have explored how Liquibase revolutionizes database management processes, emphasizing its role in supporting best practices in the field of DevOps and CI/CD. In an era of continuous change and increasing complexity of IT systems, Liquibase emerges as a key element in the arsenal of every programmer and IT team aspiring for efficiency, scalability, and reliability in their software endeavors.
References:
- https://www.liquibase.org/
Meet the geek-tastic people, and allow us to amaze you with what it's like to work with j‑labs!
Contact us


