Java.DBMigrationTools.How do you split large changelogs into modular ones?

You split large Liquibase changelogs by composition, not chronology: one master changelog that includes many small, purpose-focused changelogs.

Core idea (interview-ready)

Use a single master changelog that includes modular changelogs by domain, feature, or layer, keeping each file small and owned.

1️⃣ The master changelog (entry point)

This is the only file Spring Boot / CI points to.

databaseChangeLog:
  - include:
      file: db/changelog/schema/schema.yaml
  - include:
      file: db/changelog/data/data.yaml
  - include:
      file: db/changelog/indexes/indexes.yaml

Why this works:

  • deterministic order
  • one migration history
  • easy to reason about execution flow

2️⃣ Split by responsibility (recommended)

Common, proven structure

db/changelog/
├── db.changelog-master.yaml
├── schema/
│   ├── users.yaml
│   ├── orders.yaml
│   └── payments.yaml
├── data/
│   ├── reference-data.yaml
│   └── backfills.yaml
├── indexes/
│   └── performance.yaml

Example: schema/users.yaml

databaseChangeLog:
  - changeSet:
      id: users-001-create-table
      author: stanley
      changes:
        - createTable:
            tableName: users
            columns:
              - column: { name: id, type: bigint, constraints: { primaryKey: true } }
              - column: { name: email, type: varchar(255), constraints: { nullable: false } }

Benefits:

  • smaller PRs
  • clearer ownership
  • fewer merge conflicts

3️⃣ include vs includeAll (important distinction)

✅ Prefer include

- include:
    file: db/changelog/schema/users.yaml

Why:

  • explicit order
  • predictable diffs
  • safe for production

⚠️ Be careful with includeAll

- includeAll:
    path: db/changelog/schema

Risks:

  • order depends on filesystem / build tool
  • easy to accidentally reorder migrations
  • harder to review

📌 Senior rule: includeAll is acceptable only for append-only, strictly ordered folders with clear naming.

4️⃣ Split by lifecycle, not by environment

❌ Bad split:

prod.yaml
dev.yaml
test.yaml

✅ Good split:

schema/
data/
indexes/

Environment differences belong in:

  • contexts
  • preconditions
  • runtime config
    —not in separate core changelogs.

5️⃣ Keep changesets small and atomic

Even inside modules:

  • one intent per changeset
  • avoid “mega changesets”
  • easier rollback reasoning
  • safer reviews

6️⃣ How this helps large teams

  • Teams own their module file
  • Fewer merge conflicts
  • Clear review responsibility
  • Safer parallel work
  • Easier long-term maintenance

Interview-ready answer (2–3 sentences)

Large changelogs are split by using a single master changelog that includes multiple smaller, purpose-focused changelogs, typically organized by domain or lifecycle like schema, data, and indexes. This keeps migrations readable, reduces merge conflicts, and preserves deterministic execution order.

Senior rule of thumb (remember this)

One master changelog, many small modules, explicit includes, and no environment-driven schema splits.

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