Should Execute
Published 04 June 2024
Should Execute
Description
shouldExecute
is a script configuration option that lets you define when a migration should execute.
Unlike skipExecutingMigrations, this will not update the
schema history table.
Usage
In order to use this option, you first have to create a script configuration file which defines the conditions under which the script should be executed. This file contains the options for this migration script
Configuration File
shouldExecute=<expression>
Where expression
evaluates to a boolean value
- Either
true
orfalse
<A>==<B>
or<A>!=<B>
where<A>
and<B>
are placeholders or literal values.- Combinations of these using
&&
(AND),||
(OR) and parentheses( )
Flyway will change behavior for this migration depending on the expression evaluation:
- If it evaluates to true, this migration is executed
- If it evaluates to false, this migration is ignored
- If it fails to evaluate, an exception will be thrown
The power of this configuration comes from their integration with placeholders that allow you to set the condition for a specific script and control that condition globally.
For examples of how to use this feature, see the shouldExecute Concept page