A changeset is a single, versioned unit of change to the database schema — like a commit in version control.
It defines one or more actions (e.g. createTable, addColumn, insertData) and is tracked by the migration tool to prevent reapplication.
🔎 Detailed Explanation
🔹 In Liquibase, a changeset is defined inside a changelog file.
Each changeset has:
- a unique
id - an
author - and a set of one or more changes (like
createTable,addColumn, etc.)
✅ Example — XML format:
<changeSet id="1" author="alice">
<createTable tableName="user">
<column name="id" type="bigint" autoIncrement="true" />
<column name="username" type="varchar(255)" />
</createTable>
</changeSet>
✅ Example — YAML format:
- changeSet:
id: 2
author: bob
changes:
- addColumn:
tableName: user
columns:
- column:
name: email
type: varchar(255)
🔹 How does Liquibase use changesets?
Liquibase creates a special table in your DB called DATABASECHANGELOG.
Each time a changeset is applied, it:
- Logs the
id,author, and checksum - Marks it as executed
- Skips re-running it in future deployments
✅ This ensures idempotency — no matter how many times you deploy, the same migration isn’t re-applied.
🔹 ✅ What can a changeset do?
A changeset can:
- Create/drop tables
- Add/modify columns
- Add constraints or indexes
- Insert/update/delete data
- Call custom SQL
- Run stored procedures
- Define rollback logic (optional)
🔹 In Flyway, a changeset is an individual versioned migration file, like V2__add_email_column.sql.
It doesn’t use id and author in the same way, but conceptually each file is a changeset → tracked by Flyway’s metadata table (flyway_schema_history).
📌 Key Takeaways
✅ A changeset is the smallest tracked schema change in tools like Liquibase.
✅ Each changeset has a unique ID and author and is executed exactly once per database.
✅ It ensures safe, consistent, and automated database evolution, just like commits do for code.