Flyway and Liquibase are database migration libraries. They apply versioned schema changes (new tables, columns, indexes, seed data) to your database in a controlled order, record what has already run, and refuse to run the same change twice. In a Spring Boot application they run automatically at startup, so every environment ends up with the same schema as the code that expects it.
Without a migration tool, schema changes live in ad hoc SQL scripts or in Hibernate's ddl-auto, which is unsafe for production. A migration library turns the schema into version-controlled code that is reviewed, tested and deployed together with the application.
When several developers and several environments (local, CI, staging, production) share one schema, you need to answer three questions: which changes have been applied here, in what order should the missing ones run, and has anyone edited a change that already ran? Flyway and Liquibase answer all three by keeping a history table in the target database.
Both tools give you:
Flyway uses plain SQL files (or Java-based migrations) with a naming convention. Each file is a version, and Flyway applies pending versions in order.
V1__create_customer.sql is a versioned migration: a version number, two underscores, then a description. R__... files are repeatable migrations that re-run whenever their checksum changes, which suits views and stored procedures.
Flyway stores progress in the flyway_schema_history table. If you edit a migration that has already been applied, its checksum no longer matches and validation fails at startup. The rule is simple: never edit an applied migration, add a new one.
Liquibase describes changes as changesets inside a changelog. The changelog can be written in YAML, XML, JSON or formatted SQL, and each changeset is identified by an id and an author plus the file path.
Liquibase tracks applied changesets in the DATABASECHANGELOG table and uses DATABASECHANGELOGLOCK to stop two instances from migrating at the same time. Because changes are described abstractly, Liquibase can generate database-specific SQL for you, and you can attach rollback instructions to a changeset.
Spring Boot detects the library on the classpath and runs it before the EntityManagerFactory or application code touches the database.
Flyway:
Liquibase:
Set spring.jpa.hibernate.ddl-auto=validate (or none) so Hibernate only checks that the entities match the schema the migration tool created. Letting Hibernate alter the schema in parallel defeats the purpose.
| Aspect | Flyway | Liquibase |
|---|---|---|
| Change format | SQL files, optional Java migrations | YAML, XML, JSON or SQL changesets |
| Learning curve | Very low if you know SQL | Higher, more concepts |
| Database portability | You write SQL for your database | Abstract changes can target many databases |
| Rollback | Undo migrations are a paid-edition feature | Rollback blocks are supported per changeset |
| History table | flyway_schema_history | DATABASECHANGELOG and DATABASECHANGELOGLOCK |
| Ordering | By version number in the file name | By order of changesets in the changelog |
Pick Flyway when your team targets one database and prefers plain SQL. Pick Liquibase when you need database-independent changes, conditional changesets (preconditions) or richer rollback support. Do not use both on the same schema.
Yes. With Flyway, set a baseline (spring.flyway.baseline-on-migrate=true with a baseline version) so existing objects are treated as version 1. With Liquibase, generate a baseline changelog from the current schema and mark it as already applied.
ddl-auto with these tools?No. Use validate or none in every environment where a migration tool owns the schema. create and update are only suited to throwaway prototypes.
Both tools take a lock in the database. One instance migrates while the other waits, then finds nothing left to apply.
Liquibase supports rollback instructions per changeset. In Flyway, undo migrations are part of the paid editions, so the usual approach in the open-source edition is to write a new forward migration that reverses the change.
Flyway and Liquibase make the database schema a versioned part of your application. Spring Boot runs them at startup, records every change in a history table, and detects drift through checksums. Choose Flyway for simple, SQL-first workflows and Liquibase for database-agnostic, rollback-friendly change management, and let Hibernate only validate the result.