Java.DBMigrationTools.What formats can migration files be written in?

Migration files can be written in various formats depending on the tool:

ToolSupported Formats
FlywaySQL, Java (callbacks), JSON (limited)
LiquibaseXML, 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:

  1. 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

FormatProsCons
SQLSimple, familiarLess support for rollback or logic
XMLRich features, rollback, changelog controlVerbose
YAMLCleaner than XMLIndentation-sensitive
JSONGood for generation toolsHard to read manually
Java (Flyway)Powerful, dynamicComplex 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.

This entry was posted in Без рубрики. Bookmark the permalink.