Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway: How to run certain repeatable migrations before versioned ones?

Flyway states in its documentation some of the usages for repeatable migrations:

Usages: (Re-)creating views/procedures/functions/packages/...

I have some triggers/functions that I want to create in a repeatable migration, these are later referenced in version migrations, where they are applied to tables.

Flyway runs repeatable migrations last, which means the triggers don't exist when they are referenced.

Is it possible to run certain repeatable migrations before versioned ones?

Is this use case not supported because it would be bad practice to automatically update triggers that are applied to tables?

like image 409
Juan Jose Lenero Lozano Avatar asked Oct 30 '22 10:10

Juan Jose Lenero Lozano


1 Answers

I don't think it's possible to call repeated migration scripts first.But you can use callback scripts for your purpose. Read about it here.

So you can have a script called beforeMigrate.sql within a migration script directory and use it to initialize what you want.

Though I don't understand, why not to recreate triggers after the versioned migration is done? If you have temporary(short-living) objects like some triggers, that seems to me right, to bind them to the permanent objects in the same script they are declared - I mean in the repeated migration script.

like image 117
Stanislav Avatar answered Nov 25 '22 09:11

Stanislav