【问题标题】:Flyway migration and hibernate context, execution orderFlyway迁移和休眠上下文,执行顺序
【发布时间】:2019-03-13 13:41:54
【问题描述】:

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

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

【问题讨论】:

    标签: spring-boot flyway


    【解决方案1】:

    Spring boot 使用了一个FlywayMigrationInitializer bean(它实现了一个高阶的InitializingBean (oder = 0)),这样afterPropertiesSet就包含了flyway迁移函数:

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

    会执行Flyway.java#migrate()里面的逻辑

    开始数据库迁移。将应用所有待处理的迁移 按顺序。在最新的数据库上调用 migrate 无效。

    可以参考javadoc的Flyway.javaFlywayMigrationInitializer.javajavadoc

    【讨论】:

    • so 比如hibernate context,没有顺序设置?
    • sessionFactory bean 的定义将dependsOn Flyway bean 的定义,可以看这个example from flyway doc
    猜你喜欢
    • 2017-10-24
    • 2016-10-24
    • 2016-01-30
    • 2019-08-12
    • 2014-03-11
    • 2013-03-11
    • 2021-09-22
    • 2015-12-28
    • 1970-01-01
    相关资源
    最近更新 更多