krzakov
krzakov

Reputation: 4111

Flyway migration and hibernate context, execution order

I am using spring boot with default configuration with flyway and hibernate. I'm wondering about the execution order. According to the documentation Flyway checks the version of the database and applies new migrations automatically before the rest of the application starts.

Where can I find a source code confirming that statement? Where execution order is determined?

Upvotes: 1

Views: 465

Answers (1)

Abdelghani Roussi
Abdelghani Roussi

Reputation: 2817

Spring boot use a FlywayMigrationInitializer bean ( which implements InitializingBean with a high order ( oder = 0 ) ), so that afterPropertiesSet which contains the flyway migration function :

@Override
public void afterPropertiesSet() throws Exception {
    if (this.migrationStrategy != null) {
        this.migrationStrategy.migrate(this.flyway);
    }
    else {
        this.flyway.migrate();
    }
}

will execute the logic inside Flyway.java#migrate() which

Starts the database migration. All pending migrations will be applied in order.Calling migrate on an up-to-date database has no effect.

You can refer to the Flyway.java of javadoc and FlywayMigrationInitializer.java javadoc

Upvotes: 2

Related Questions