Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks are added and executed multiple times #1625

hmtelbi opened this issue May 9, 2017 · 3 comments

Callbacks are added and executed multiple times #1625

hmtelbi opened this issue May 9, 2017 · 3 comments


Copy link

hmtelbi commented May 9, 2017

What version of Flyway are you using?


Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)

Java API

What database are you using (type & version)?

Oracle 12c ( / 64 Bit)

What operating system are you using?

Windows 7 (64 Bit) / JDK 1.8.0_131

What did you do?
  • updated from FlywayDB version 4.0.3 to 4.2.0
  • defined a beforeBaseline.sql callback script
  • invoked and then flyway.baseline()
What did you expect to see?

The beforeBaseline.sql script should be executed only once.

What did you see instead?

The beforeBaseline.sql script has been executed twice:

2017-05-09 17:26:03.778 [INFO ] o.f.c.i.c.SqlScriptFlywayCallback: Executing SQL callback: beforeBaseline
2017-05-09 17:26:03.816 [INFO ] o.f.c.i.c.SqlScriptFlywayCallback: Executing SQL callback: beforeBaseline
Additional information

It seems that this bug has been introduced in commit 0baf57e, which changed the execute method in

/*private -> testing*/ <T> T execute(Command<T> command) {
        if (!skipDefaultCallbacks) {
            Set<FlywayCallback> flywayCallbacks = new LinkedHashSet<FlywayCallback>(Arrays.asList(callbacks));
                    new SqlScriptFlywayCallback(dbSupport, scanner, locations, createPlaceholderReplacer(), this));
            callbacks = flywayCallbacks.toArray(new FlywayCallback[flywayCallbacks.size()]);

Whenever the execute method is invoked (and skipDefaultCallbacks is not set), an additional SqlScriptFlywayCallback instance is added to the callbacks property.

@axelfontaine axelfontaine added this to the Flyway 5.0.0 milestone May 9, 2017
Copy link

configman commented Jun 19, 2017

This appears to affect default SQL callbacks on the command line as well (certainly the beforeMigrate and afterMigrate ones). I'm using V4.2.0 and have placed beforeMigrate.sql and afterMigrate.sql in the flyway location and am seeing duplicate 'Executing SQL callback;' messages.

Copy link

It appears that what I was seeing is that the beforeMigrate.sql and afterMigrate.sql scripts are run for the clean and the migrate command when running 'flyway clean migrate'. But, the additional executions are not before or after the clean phase, they are around the migrate phase.

I realised this when I ran a migrate on a fully up-to-date schema (I wanted to check whether the callbacks are executed when there are no migrations that are required to be run). In this situation there is a single execution of the relevant script rather than two. Adding an (unnecessary) repair to the command line (flyway repair clean migrate) results in three executions of each of the beforeMigrate and afterMigrate callback scripts.

Copy link

Well spotted. This has now been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants