Is there any way to control execution order of repeatable migration scripts in flyway? I want to run a repeatable migration script after all other repeatable or versioned scripts on checksum change.
-
I didnot understand your requirement but i guess you are looking for a way to perform migrations without any order .If that is what you need use this "outOfOrder" .Set this value to true – Aston Ray Mar 28 '16 at 11:37
-
But there is a potential problem with this option.Verify your migration files with the schema_version table for any missed scripts . – Aston Ray Mar 28 '16 at 11:55
-
We can specify execution order of versioned migration scripts simply by setting version number. But I didn't find any way to sort execution of repeatable migration scripts. My question was about repeatable migrations. outOfOrder is about versioned mirgrations. – Seyyed Jamal Mar 29 '16 at 07:25
2 Answers
Repeatable scripts appear to be controlled by the name following the R__
suffix
, first numeric
, then alpha upper case
, then alpha lower case
.
Instead of being run just once, they are (re-)applied every time their checksum changes.
Within a single migration run, repeatable migrations are always applied last, after all pending versioned migrations have been executed.
https://flywaydb.org/documentation/migrations#repeatable-migrations

- 360
- 7
- 19

- 266
- 2
- 2
-
16For what flyway calls *repeatable* scripts, you can specify order by doing the following: R__01_mustberunfirst.sql, R__02_mustberunsecond.sql etc... – johnm May 24 '16 at 08:13
Maybe naming the scripts in the right order is not enough. If you name them R__A
, R__B
and R__C
, it works for the first time, but when you later only change R__B
, then only R__B
will be executed. This may be a problem, if subsequent scripts should be re-executed but did not change. For example, R__B
creates a table and R__C
inserts some static data.
-
1Then what else should be done to control the order? Stating that something does not work does not look like a solution for the problem – Nico Haase Aug 17 '18 at 08:00
-
2The aforementioned problem can now be solved with the built-in `${flyway:timestamp}` substitution, which may be added before each repeatable migration (_e.g._ as an SQL comment). – Priidu Neemre Dec 01 '20 at 09:05