den*_*ron 5 flyway spring-boot
将 springboot 2.0.3 升级到 2.1.1 也带来了一个新的 Flyway 版本:5.2.3 而不是 5.0.7。
在 5.2.3 SpringJdbcMigration 已弃用,将在 flyway 6 中删除。我主要使用 sql 脚本,但我在项目中也有一个 java 迁移类(有 4 个 sql 迁移,最后一个 4.2 是 java 迁移-更改旧数据只是一些快速而肮脏的黑客攻击,我不再需要它了)。
所以我改变了那个班级:
class V4_2__Update_foo implements SpringJdbcMigration {
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
...
}
}
Run Code Online (Sandbox Code Playgroud)
到
class V4_2__Update_foo extends BaseJavaMigration {
public void migrate(Context context) throws Exception {
JdbcTemplate jdbcTemplate =
new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
......
}
}
Run Code Online (Sandbox Code Playgroud)
这是唯一的变化,其他一切都一样。结果是
Application run failed
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]:
Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException:
Validate failed: Migration type mismatch for migration version 4.2
....
Caused by: org.flywaydb.core.api.FlywayException:
Validate failed: Migration type mismatch for migration version 4.2
-> Applied to database : SPRING_JDBC
-> Resolved locally : JDBC
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1479)
Run Code Online (Sandbox Code Playgroud)
我不想永久禁用验证,但我也不知道如何解决这个问题。我试过谷歌搜索,但没有发现任何关于“类型不匹配”的信息。在我的开发机器上,我尝试了“flyway repair”,但它只说
Repair of failed migration in Schema History table "PUBLIC"."schema_version" not necessary. No failed migration detected.
Successfully repaired schema history table "PUBLIC"."schema_version"
Run Code Online (Sandbox Code Playgroud)
运行修复后迁移4.2的类型仍然是“SPRING_JDBC”。后来我完全删除了java类,这给了我一个警告
Schema "PUBLIC" has a version (4.2) that is newer than the latest available migration (4) !
Run Code Online (Sandbox Code Playgroud)
但至少应用程序再次运行。不过,我在生产中这样做并不是很舒服。还有其他想法吗?
这绝对是一个错误。不幸的是,这个问题不会在 5.2.x 中得到修复。Flyway 6.0(将于 2019 年第一季度发布)将自动更正您的架构历史表并修复此问题。
或者,如果您确实不想等待,则可以手动查找架构历史记录表以使此消息消失。
| 归档时间: |
|
| 查看次数: |
2640 次 |
| 最近记录: |