✅ Short Answer
A changelog file is a version-controlled file that defines the sequence of changes to apply to your database schema over time.
It acts as the master plan for database migrations.
🔎 Detailed Explanation
A changelog file:
- Lists all the migration steps (change sets) in the order they should be applied.
- Tells the migration tool how to evolve the database.
- Can include version numbers, authors, timestamps, and rollback logic.
It’s like a Git history for your database schema.
🔹 Tool-specific examples
✅ Liquibase changelog (XML/YAML/JSON/SQL)
XML Example:
<databaseChangeLog
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-3.8.xsd">
<changeSet id="1" author="dev">
<createTable tableName="users">
<column name="id" type="int" autoIncrement="true"/>
<column name="username" type="varchar(255)"/>
</createTable>
</changeSet>
<changeSet id="2" author="dev">
<addColumn tableName="users">
<column name="email" type="varchar(255)"/>
</addColumn>
</changeSet>
</databaseChangeLog>
✅ The changelog file:
- Contains multiple
changeSetblocks (like commits). - Is tracked by Liquibase to avoid re-running changes.
- Can be split into multiple files and include them via
<include>.
✅ Flyway doesn’t use a central changelog file, but instead uses:
- Multiple versioned SQL files, like:
V1__init_schema.sql
V2__add_users.sql
V3__add_email_column.sql
✅ These files are stored in resources/db/migration and applied in version order.
✅ The filename itself is the changelog.
🔹 Why changelog files matter
- They provide a history of how the schema evolved
- They let you recreate the schema from scratch
- They ensure every environment evolves the same way
- They support rollback, tagging, branching, and more
📌 Key Takeaways
✅ A changelog file defines the full evolution of your database schema.
✅ In Liquibase, it’s an XML/YAML/JSON/SQL file containing changeSets.
✅ In Flyway, it’s a collection of ordered versioned files.
✅ It ensures safe, reproducible, automated migrations across all environments.