Skip to content

Database migrations with Flyway

Version control/management of updates

Using Flyway for database version control

  • Recommendations:
  • Use timestamp to tag migration. Makes it easier to manage especially if you're going to be in a multi-developer environment
  • Use git to track migrations - flyway notices if a migration file changes and causes issues

Setting up flyway

  • Sqlite jdbc driver - xerial/sqlite-jdbc - for prototyping
  • Postgresql JDBC Driver - Postgresql
  • Flyway ant library - Flyway Ant
  • Directory Structure
  • db
    • conf/
    • flyway.conf
    • libs/
    • flyway/ # Flyway ant
    • postgresql-9.4.1212.jar
    • ant-contrib-1.0b3.jar
    • migrations
    • build.xml
  • Using the serial date for tracking migrations - date +%s

Using ant to run migrations

  • Using SDKMAN to manage ant - sdkman | Ant
  • Added Ant contrib jar
  • Libs used
  • ant-contrib-1.0b3.jar -- ant contrib jar - (Ant contrib task)[]
  • postgresql-9.4.1212.jar -- Postgresql
  • flyway - has the flyway core and ant libraries -- Flyway Ant
  • build.xml in db library

Deleting a migration.

Can't delete a migration, only repair it.

  1. Comment out the commands in the migration mistake you are eliminating.
  2. Run ant repair to fix the checksums for the migrations
  3. Validate the current tatus ant validate
  4. Flyway should be back to the status it is suppose to be in.