Flyway and Liquibase are database migration tools. They version-control your database schema by applying an ordered set of changes (migrations) to each environment and recording which ones have run. That makes schema changes repeatable, reviewable in Git, and safe to roll out together with the application code.
Spring Boot supports both out of the box: add the dependency, place migration files in the expected folder, and they run at startup before your JPA or JDBC code uses the schema.
Without migrations, teams change schemas by hand or with spring.jpa.hibernate.ddl-auto=update. That drifts between environments, cannot be reviewed, and can silently lose data. A migration tool provides:
Treat applied migrations as immutable. Fix mistakes with a new migration, never by editing an old one.
Flyway uses plain SQL files (or Java migrations) with a version in the file name. It stores history in the flyway_schema_history table.
V<version>__<description>.sql is a versioned migration, applied once in order.R__<description>.sql is a repeatable migration, re-applied whenever its checksum changes (useful for views and functions).In Spring Boot add the core library, plus the database module required by recent Flyway versions (from Flyway 10 each database has its own module):
Liquibase describes changes in a changelog written in YAML, XML, JSON or formatted SQL. Each change is a changeset identified by id and author, tracked in the DATABASECHANGELOG table.
Because changes are described abstractly (createTable), Liquibase can generate SQL for several database vendors from one changelog, and you can attach preconditions, contexts, labels and rollback blocks.
| Aspect | Flyway | Liquibase |
|---|---|---|
| Main format | SQL files, Java migrations | YAML, XML, JSON, SQL |
| Ordering | Version number in file name | Order of changesets in changelog |
| History table | flyway_schema_history | DATABASECHANGELOG |
| Multi-database abstraction | Write SQL per database | Built in via change types |
| Rollback | Undo migrations are a paid-edition feature | Rollback blocks supported |
| Learning curve | Very low | Moderate |
Pick Flyway when your team is comfortable with SQL and runs a single database engine. Pick Liquibase when you need vendor-neutral changelogs, preconditions, contexts or declarative rollback. Check each project's current licensing and edition features before standardizing, as they change between releases.
ddl-auto=update with a migration tool; set it to validate or none.For a database that already has tables, baseline it so the tool starts from the current state. In Flyway use spring.flyway.baseline-on-migrate=true with a baseline-version. In Liquibase generate a starting changelog with the generateChangeLog command and mark it as already applied.
You can technically, but you should not. Two tools managing one schema create conflicting histories. Choose one.
Yes. When Flyway or Liquibase is on the classpath and a DataSource exists, Spring Boot auto-configures it and runs migrations at startup.
Flyway fails validation because of a checksum mismatch, and Liquibase fails for changesets whose checksum changed. Add a new migration instead.
Not for production. It cannot track history, review changes or handle data migration. Use it only for throwaway prototypes.
Flyway and Liquibase apply versioned, auditable schema changes automatically and record them in a history table. Flyway favors plain SQL and simplicity, Liquibase favors abstract, multi-database changelogs and rollback. Whichever you choose, keep applied migrations immutable, validate them in CI, and design changes to be safe during rolling deployments.