The flyway_schema_history table is a metadata table automatically created by Flyway in your database.
It records which migrations have been applied, in what order, by whom, and when — ensuring each migration is executed exactly once.
🔎 Detailed Explanation
When you run flyway migrate, Flyway:
- Checks if
flyway_schema_historyexists — if not, it creates it - Scans your migration files (e.g.,
V1__init.sql,V2__add_table.sql) - Compares them against what’s already been recorded
- Applies only the new (unapplied) migrations
- Logs each successfully applied migration as a new row
📋 Key Columns in flyway_schema_history
| Column Name | Description |
|---|---|
installed_rank | Order of execution (starts at 1) |
version | Version number (e.g., 1, 2.1, 3.0) |
description | Human-friendly name (from filename, like create_users_table) |
type | Type of migration (SQL, JDBC, UNDO, REPEATABLE) |
script | Exact filename applied (V2__add_email_column.sql) |
checksum | Hash of the file contents for integrity verification |
installed_by | Database user who executed the migration |
installed_on | Timestamp when migration was applied |
success | Whether the migration succeeded (1 for success, 0 for failure) |
🧠 Why It Matters
- ✅ Prevents Flyway from re-applying the same migrations
- ✅ Detects checksum mismatches if a migration file is modified
- ✅ Ensures your environments stay in sync
- ✅ Enables repeatable migrations and undo tracking
🔄 Example Entry
| installed_rank | version | description | script | success |
|---|---|---|---|---|
| 1 | 1 | init_schema | V1__init_schema.sql | 1 |
| 2 | 2 | add_users_table | V2__add_users_table.sql | 1 |
| 3 | 3 | add_index_on_email | V3__add_index_on_email.sql | 1 |
📌 Key Takeaways
✅ flyway_schema_history is Flyway’s way of tracking migration progress
✅ Ensures that every migration is applied exactly once and in order
✅ Enables rollback, validation, and schema safety across environments