Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does flyway produce a warning message when setting outOfOrder to true?

Tags:

java

flyway

I am getting the following warning message in my logs when outOfOrder is set to true:

WARNING: outOfOrder mode is active. Migration run may not be reproducible.

What is the exact meaning of this message? It will be good if someone can tell me what would happen when migration happens. Any example would be helpful.

like image 814
user1862868 Avatar asked Mar 06 '13 08:03

user1862868


People also ask

What is flyway Outoforder?

Description. Allows migrations to be run “out of order”. If you already have versions 1.0 and 3.0 applied, and now a version 2.0 is found, it will be applied too instead of being ignored.

Why am I getting an error when creating Flyway migrations?

Cause: The code is missing a migration script that was previously applied to the database. This can happen when multiple people are creating Flyway migrations at the same time. In that case, update your code, so it includes the migration script specified in the error message.

What is Flyway out of order?

flyway.outOfOrder - Out Of Order - Flyway by Redgate • Database Migrations Made Easy. Allows migrations to be run “out of order”. If you already have versions 1.0 and 3.0 applied, and now a version 2.0 is found, it will be applied too instead of being ignored.

How does Flyway preserve the state of the database?

To preserve the state of the database schema, flyway creates and stores metadata about all applied schema migration in an own table (see picture below). The table shows in which order, which script has been applied and when.

How to execute multiple migrations at the same time in Flyway?

To allow executing this migration, set -outOfOrder=true This can happen when multiple people are creating Flyway migrations at the same time, since by default, Flyway expects the migrations to be applied in order according to the version number. Let’s say you worked on migration version 2.0 and applied it to the database.


Video Answer


2 Answers

Assume 3 migrations:

  1. Create two names 'Tom' and 'Jerry'
  2. Add 'Mickey' as a 3rd one
  3. Turn names into uppercase

Running with outOfOrder may result in say your migrations applied like this:

1, 3, 2 -> In the DB: TOM, JERRY, Mickey

Re-running it later will produce

1, 2, 3 -> In the DB: TOM, JERRY, MICKEY

This is why outOfOrder is potentially dangerous and the first migration run might not be reproducible.

like image 53
Axel Fontaine Avatar answered Oct 21 '22 21:10

Axel Fontaine


To add to Axel's answer, not only may the resulting data vary depending on the order, but the migration may not even be possible. Consider:

Migrations:

  1. Create table foo
  2. Add column foo.bar
  3. Rename column foo.bar to foo.baz

Execution order:

  • 1, 2, 3 → foo has column baz
  • 1, 3, … → error applying 3: column foo.bar not found
  • 2, … → error applying 2: table foo not found
  • 3, … → error applying 3: table foo not found
like image 25
pimlottc Avatar answered Oct 21 '22 23:10

pimlottc