Java.DBMigrationTools.Can you use both Liquibase and Flyway in the same project?

Short answer: yes, technically you can — but in 99% of real projects you shouldn’t.
In interviews, this is a trap question. What matters is why and how.


Short interview answer (what you say in 20–30 seconds)

“Technically it’s possible to use Liquibase and Flyway in the same project, but it’s strongly discouraged. Both tools manage schema history and migrations, so mixing them increases operational risk. The only acceptable case is a controlled transition where one tool is frozen and the other takes over, with clear ownership of different migration phases.”

If you say this calmly and confidently → senior signal.


Why mixing Liquibase & Flyway is a bad idea

1. Two sources of truth

  • Flyway → flyway_schema_history
  • Liquibase → DATABASECHANGELOG, DATABASECHANGELOGLOCK

You now have two independent migration graphs.

👉 No single answer to:

  • “What version is the DB at?”
  • “Which migration ran first?”

2. Ordering conflicts

  • Flyway: linear, version-based (V1__, V2__)
  • Liquibase: changeSets with IDs, supports branching, contexts, labels

Example problem:





Liquibase adds column A
Flyway assumes column A already exists

Boom — prod failure.

3. Operational complexity

  • CI/CD pipelines need to:
    • run Liquibase
    • then Flyway
    • in the correct order
  • Rollbacks become unclear
  • On-call debugging becomes painful

Senior engineers hate this.


4. Team cognitive load

New engineer asks:

“Where do I put my migration?”

Wrong answer:

“Depends.”


When it can make sense (rare but valid)

1. Gradual migration from one tool to another

This is the only strong justification.

Example:

  • Legacy project uses Liquibase
  • Company standardizes on Flyway
  • Strategy:
    • Liquibase → frozen (no new changeSets)
    • Flyway → only new migrations

Important rules:

  • Clear cutoff date
  • Clear ownership
  • One-way transition

2. Different databases (edge case)

Example:

  • Liquibase manages core schema
  • Flyway manages read-only reporting DB

Still risky, but defensible.


3. Vendor product constraints

Rare enterprise case:

  • Vendor forces Liquibase
  • Internal services use Flyway

You isolate them strictly.


How to do it safely (if forced)

If interviewer asks “HOW would you do it?” — answer like this:

Rules

  1. Never touch the same tables
  2. One tool is read-only
  3. Explicit execution order
  4. Documented ownership

Example setup

Liquibase:
  - baseline schema
  - frozen after v2023_12

Flyway:
  - V2024_01__add_indexes.sql
  - V2024_02__optimize_queries.sql

What interviewers are really testing

They want to see if you understand:

  • Migration ownership
  • Idempotence
  • Operational safety
  • Blast radius in production

If you answer:

“Yes, we can use both, why not?”

❌ Junior / mid signal.

If you answer:

“Yes, but only for transition and with strict rules.”

✅ Senior signal.


Bonus: Flyway vs Liquibase — how to explain the difference fast

AspectFlywayLiquibase
StyleSQL-firstDSL / XML / YAML
ModelLinearGraph-based
RollbackForward-onlySupports rollback
ComplexityLowHigh
Enterprise featuresLimitedRich
This entry was posted in Без рубрики. Bookmark the permalink.