1. Overview

In this article, We will learn how we can configure repeatable migration in the flyway database migration tool with an example. So many times it needs for us to run the script every time when changes are applied, for example, any changes in store procedure then we like to execute again when the application deployed to the server.

2. Flyway Repeatable Migration Rules

Repeatable migration might be used for:

  • Create or Replace store procedure or function
  • Every time insert some new record into the table

Rules for Repeatable Migration

  • Repeatable migration will execute after executing pending version migration.
  • We should be careful about CREATE OR REPLACE statement because while executing the second time database will not allow creating same name object (Table, Stored Procedure or Function) we need to use CREATE OR REPLACE statement not only CREATE statement.

In our previous articles, we learned about how we can execute java logic to migration database using Flyway Now lets start about repeatable migrations.

CALLBACK : We can also implement repetable using callback but with specific perpose. here is more details about callback

3. Example

  1. Create a .sql file with R__ so it will be executed rapidly when any changes applied to file, do not write version here.  Here is flyway example with spring boot application.
Flyway Repeatable Migration

Flyway Repeatable Migration

4. References

5. Source Code

spring-boot-Flyway-database-migration-example (46 KB)

 

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *