Repeatable flyway migration won't run again if placeholder changes

1.2k Views Asked by At

i'm using a repeatable flyway migration that does some data mangling which under circumstances should be run more than once. I put a placeholder value like ${TRIGGER_DATA_UPDATE} in a comment in the migration .sql code. The idea is to change this placeholder value from flyway.conf (or a bash script that alters the flyway.conf) and make the repeatable migration run.

As far as i've seen, changing the placeholder doesn't cause the repeatable migration to run again. It will only run once. It looks as if the checksum calculation does not take into account placeholder values.

Is this a feature or a bug ?

On the contrary, if i edit the comment directly inside the repeatable migration the change is detected and the migration will run in the next invocation of flyway.

Here is the repeatable migration .sql file:

    -- The following line will trigger execution of this script appropriately when upgrade.shis executed
    /* ${TRIGGER_DATA_UPDATE} */
    UPDATE  restcomm_accounts SET password = auth_token, password_algorithm = 'md5' WHERE password IS NULL;

The TRIGGER_DATA_UPDATE is the placeholder value.

And here is the important part of flyway.conf:

    flyway.placeholders.TRIGGER_DATA_UPDATE=this_part_changes
1

There are 1 best solutions below

0
On

You are right, checksum calculation is on the file contents (only). This appears to be by design; SqlMigrationResolver.java.

As a workaround you may be able to put this into a callback and have it run conditionally. I assume you are on the command line (as you mentioned bash) so it would be put into afterMigrate.sql. You'll either need to use your database's programming language (eg PLSQL) or be creative with the where statement. Make sure you turn on debug (-X) so the callback is logged. It will be executed even when migrate doesn't actually run any migrations (ie no pending).

Try the following:

-- The following line will trigger execution of this script appropriately when upgrade.shis executed
UPDATE  restcomm_accounts SET password = auth_token, password_algorithm = 'md5' WHERE password IS NULL
AND '${TRIGGER_DATA_UPDATE}' = 'Y'
;