DEV Community

Pranav Bakare
Pranav Bakare

Posted on

Liquibase, ChangeSet, and ChangeLog

Here are concise definitions for Liquibase, ChangeSet, and ChangeLog:

  1. Liquibase:
    A database schema change management tool that helps developers track, version, and automate database changes across environments in a structured and consistent way.

  2. ChangeSet:
    A single unit of change in Liquibase, representing a specific database operation, such as creating a table, adding a column, or updating data. Each changeset is uniquely identified by an id, author, and the changelog file.

  3. ChangeLog:
    A file in XML, YAML, JSON, or SQL format that contains a list of changesets. It serves as a record of all database changes and defines the order in which they should be applied.

.
.
.

Liquibase is an open-source database schema change management tool that allows developers to track, manage, and apply database changes across environments in a version-controlled manner. It uses a structured approach with concepts like changelogs and changesets to manage database updates.

Key Concepts in Liquibase

  1. Liquibase Changelog:

A changelog is a file that acts as a manifest to track all the database changes.

It contains a list of changesets, specifying the sequence in which they should be executed.

The changelog can be written in XML, YAML, JSON, or SQL.

Example:

xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd">

<changeSet id="1" author="user">
    <createTable tableName="users">
        <column name="id" type="int" autoIncrement="true">
            <constraints primaryKey="true"/>
        </column>
        <column name="username" type="varchar(255)"/>
        <column name="password" type="varchar(255)"/>
    </createTable>
</changeSet>
Enter fullscreen mode Exit fullscreen mode

.
.
.

  1. Liquibase Changeset:

A changeset represents an atomic unit of change that you want to apply to your database.

Each changeset is uniquely identified by its id, author, and changelog file. This ensures the same changeset is not applied multiple times.

A changeset can contain operations like creating tables, adding columns, altering tables, etc.

Example:

  • changeSet: id: 1 author: user changes:
    • createTable: tableName: users columns: - column: name: id type: int autoIncrement: true constraints: primaryKey: true - column: name: username type: varchar(255) - column: name: password type: varchar(255)

.
.
.

  1. Tracking and Managing Changes:

Liquibase maintains a table in the database (e.g., DATABASECHANGELOG) to keep track of applied changesets.

Before running a changeset, Liquibase checks this table to ensure the changeset hasn't been applied already, preventing duplicate changes.

Summary of Components

Use Case

Liquibase is ideal for automating database migrations in CI/CD pipelines, version-controlling database changes, and ensuring consistency across environments.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay