Liquibase
- Rohan Roy

- Dec 17, 2025
- 2 min read
What is Liquibase?
Liquibase is an open-source "version control for your database." Just as Git tracks changes to your application code, Liquibase tracks changes to your database schema (tables, columns, indexes).
In traditional development, managing database changes is often manual and risky: one developer runs a CREATE TABLE script locally but forgets to give it to the team, or the production database drifts out of sync with development. Liquibase solves this by treating database changes as code that can be reviewed, tested, and deployed automatically.
How Liquibase Works: The Core Architecture
Liquibase operates on a simple principle: it compares a Changelog (what you want the database to look like) against a Tracking Table (what the database actually looks like) and applies only the missing pieces.
1. The Changelog and Changesets
The heart of Liquibase is the Changelog file. Inside this file, you define units of change called Changesets.
Formats: You can write these in SQL, XML, YAML, or JSON.
Database Agnostic: If you use XML/YAML/JSON, Liquibase translates your instructions (e.g., addColumn) into the specific SQL syntax for whatever database you are using (MySQL, PostgreSQL, Oracle, etc.).
2. Tracking Progress: The Metadata Tables
When you first run Liquibase against a database, it automatically creates two tracking tables:
DATABASECHANGELOG: This acts as a ledger. Every time a changeset is successfully executed, Liquibase records the id, author, and a checksum (a digital fingerprint of the code).
DATABASECHANGELOGLOCK: This ensures that if two people (or two automated pipelines) try to update the database at the same time, one will wait for the other to finish, preventing corruption.
3. The Execution Flow
Read: Liquibase reads your Changelog file.
Compare: It queries the DATABASECHANGELOG table in your database.
Identify: It identifies which changesets in the file have not been recorded in the table yet.
Execute: It runs the new changesets in order.
Record: Once a change is finished, it adds a new row to the tracking table so it never runs that specific change again.
Key Features
Rollbacks: Liquibase can automatically "undo" many changes. For example, if a createTable fails halfway through a deployment, Liquibase can run a dropTable to return the database to its original state.
Contexts and Labels: You can tag changesets to run only in specific environments. For example, you might have a "test-data" context that only runs on your QA servers but never in Production.
Preconditions: You can add "safety checks" to a change. For instance, "Only run this addColumn script if the table users already exists."
Diff and Drift Detection: Liquibase can compare two databases (e.g., Staging vs. Production) and generate a report of the differences or even a script to sync them.
Why use it?
Feature | Benefit |
Automation | Integrates with CI/CD tools like Jenkins or GitHub Actions. |
Consistency | Ensures every environment (Dev, Test, Prod) is exactly the same. |
Collaboration | Developers can share database changes via Git just like application code. |
Audit Trail | You always know who changed what and when by looking at the tracking table. |
good stuff!