Migration files can be written in various formats depending on the tool:
| Tool | Supported Formats |
|---|---|
| Flyway | SQL, Java (callbacks), JSON (limited) |
| Liquibase | XML, YAML, JSON, SQL |
🔎 Detailed Explanation
✅ Flyway
Flyway’s primary format is versioned SQL files, e.g.:
V1__create_users_table.sql
V2__add_email_column.sql
- Pure SQL → Easy to write and read
- Runs in order based on the filename prefix (
V1__,V2__, etc.) - Supports Java-based migrations if you need programmatic logic (e.g. for complex data transformations)
🟡 Limited support for JSON in Flyway Teams (not standard)
✅ Liquibase
Liquibase supports multiple formats, all interchangeable:
- XML — most feature-rich and common
<changeSet id="1" author="alice">
<createTable tableName="users">
<column name="id" type="bigint" autoIncrement="true"/>
<column name="username" type="varchar(255)"/>
</createTable>
</changeSet>
YAML — cleaner and more readable
- changeSet:
id: 1
author: alice
changes:
- createTable:
tableName: users
columns:
- column:
name: id
type: bigint
autoIncrement: true
JSON — useful for programmatic generation, but less readable
SQL — useful if you prefer to write SQL manually
Example: db.changelog.sql
🔹 Choosing a format
| Format | Pros | Cons |
|---|---|---|
| SQL | Simple, familiar | Less support for rollback or logic |
| XML | Rich features, rollback, changelog control | Verbose |
| YAML | Cleaner than XML | Indentation-sensitive |
| JSON | Good for generation tools | Hard to read manually |
| Java (Flyway) | Powerful, dynamic | Complex to write and maintain |
📌 Key Takeaways
✅ Flyway mainly uses SQL files; optional Java if needed.
✅ Liquibase supports XML, YAML, JSON, and SQL, giving you flexibility.
✅ Choose a format based on your team’s comfort and your need for readability vs. power.