Flyway迁移和休眠上下文、执行顺序

Flyway migration and hibernate context, execution order

我正在使用 spring 引导,默认配置带有 flyway 和休眠。我想知道执行顺序。 根据文档 Flyway checks the version of the database and applies new migrations automatically before the rest of the application starts.

在哪里可以找到确认该声明的源代码?执行顺序在哪里确定?

Spring 引导使用 FlywayMigrationInitializer bean(它以高阶( oder = 0 )实现 InitializingBean ),因此afterPropertiesSet,其中包含飞路迁移功能:

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

将执行 Flyway.java#migrate() 中的逻辑,其中

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

你可以参考Flyway.java of javadoc and FlywayMigrationInitializer.javajavadoc