Introduction
A database migration tool:
- Versions db schema
- Safe, repeatable, ordered migrations
- Auto apply DB changes (Auto-run on app startup)
- Keep DB schema in sync with code
// like Git for your db schema
Without Flyway ❌:
- Everyone manually runs SQL scripts
- Different devs have different DB versions
- Production DB changes are risky
- Hard to rollback or track changes
How Flyway work:
- SpringBoot app start
- SpringBoot auto-detects Flyway if:
- flyway-core dependency exists
- A DataSource is configured
- Flyway starts migrates DB before hibernate.
- Flyway uses Spring’s DataSource to connect target DB.
- Check flyway_schema_history table.
- If not existed: auto-create it.
- Existed: reads migration history.