Flyway is a lightweight, Java-based database migration tool that helps you version, manage, and automate schema changes using plain SQL or Java migration scripts.
It’s simple, fast, and widely used in microservices, CI/CD pipelines, and Spring Boot projects.
🔎 Detailed Explanation
Flyway works by:
- Keeping a migration history table (
flyway_schema_history) in your database - Applying migration files in order, based on version numbers in filenames (e.g.
V1__init.sql) - Ensuring each migration is only applied once per environment
- Supporting both forward migrations and undo scripts
🛠️ Typical Workflow
- You create a migration file:
V1__create_users_table.sql
Flyway runs it and logs it in flyway_schema_history
You create the next version:
V2__add_email_to_users.sql
Flyway detects the new file and applies it
💡 File Naming Convention
| File Name | Meaning |
|---|---|
V1__init.sql | Version 1 – initial setup |
V2__add_column.sql | Version 2 – add a column |
U2__undo_add_column.sql | Undo script for version 2 (optional) |
R__seed_data.sql | Repeatable migration (re-runs on change) |
✅ Features
- Supports SQL-based and Java-based migrations
- Works with almost any RDBMS (PostgreSQL, MySQL, Oracle, etc.)
- Easy to plug into Spring Boot
- Supports baseline, repair, clean, and undo
- Integrates well with CI/CD tools like Jenkins, GitLab, etc.
📌 Key Takeaways
✅ Flyway is a simple, reliable tool for versioning your database schema
✅ Uses a filename-based versioning system and a tracking table
✅ Works well with SQL or Java, and is especially popular in Spring Boot ecosystems
✅ Keeps your environments in sync and repeatable