Java.DBMigrationTools.What is the flyway_schema_history table?

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:

  1. Checks if flyway_schema_history exists — if not, it creates it
  2. Scans your migration files (e.g., V1__init.sql, V2__add_table.sql)
  3. Compares them against what’s already been recorded
  4. Applies only the new (unapplied) migrations
  5. Logs each successfully applied migration as a new row

📋 Key Columns in flyway_schema_history

Column NameDescription
installed_rankOrder of execution (starts at 1)
versionVersion number (e.g., 1, 2.1, 3.0)
descriptionHuman-friendly name (from filename, like create_users_table)
typeType of migration (SQL, JDBC, UNDO, REPEATABLE)
scriptExact filename applied (V2__add_email_column.sql)
checksumHash of the file contents for integrity verification
installed_byDatabase user who executed the migration
installed_onTimestamp when migration was applied
successWhether 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_rankversiondescriptionscriptsuccess
11init_schemaV1__init_schema.sql1
22add_users_tableV2__add_users_table.sql1
33add_index_on_emailV3__add_index_on_email.sql1

📌 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

This entry was posted in Без рубрики. Bookmark the permalink.