Flyway:如何在不获取"FlywayException:验证失败"的情况下替换不推荐使用的SpringJdbcMigration? [英] Flyway: How to replace deprecated SpringJdbcMigration without getting "FlywayException: Validate failed"?

查看:252
本文介绍了Flyway:如何在不获取"FlywayException:验证失败"的情况下替换不推荐使用的SpringJdbcMigration?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将springboot 2.0.3升级到2.1.1还带来了一个新的flyway版本:5.2.3而不是5.0.7.

Upgrading springboot 2.0.3 to 2.1.1 also brings a new flyway version: 5.2.3 instead of 5.0.7.

在5.2.3中,不推荐使用SpringJdbcMigration,它将在flyway 6中删除.我主要使用sql脚本,但是我在项目中也有一个Java迁移类(有4个sql迁移,最后一个是4.2,是Java迁移-更改旧数据只是一些快速而肮脏的技巧,我不再需要它.

In 5.2.3 SpringJdbcMigration is deprecated and will be removed in flyway 6. I use sql scripts mostly, but I also have one java migration class in a project (there are 4 sql migrations and the last one, 4.2, is a java migration - it was just some quick and dirty hack to change old data and I don't need it anymore).

所以我改变了那个班级:

So I changed that class:

class V4_2__Update_foo implements SpringJdbcMigration {
    public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
    ...
    }
}

class V4_2__Update_foo extends BaseJavaMigration {
    public void migrate(Context context) throws Exception {
    JdbcTemplate jdbcTemplate = 
      new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
    ......
    }
}

这是唯一的更改,其他所有内容都相同.结果是

This is the only change, everything else is the same. The result is

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)

我不想永久禁用验证,但是我也不知道如何解决此问题.我尝试使用Google搜索,但未发现与类型不匹配"有关的任何信息. 在我的开发人员机器上,我尝试了飞车维修",但只说了

I don't want to disable validation permanently, but I also don't know how to solve this. I tried googling but found nothing concerning "type mismatch". On my developer machine I tried "flyway repair", but it only said

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"

运行修复后,迁移4.2的类型仍为"SPRING_JDBC". 后来我完全删除了Java类,这使我得到

The type of migration 4.2 is still "SPRING_JDBC" after running repair. Later I deleted the java class completely which got me a warning that

Schema "PUBLIC" has a version (4.2) that is newer than the latest available migration (4) !

,但至少该应用程序再次运行.不过,我在生产中确实不太满意.还有其他想法吗?

but at least the application was running again. I'm not really comfortable doing that in production, though. Any other ideas?

推荐答案

那肯定是一个错误.不幸的是,这不会在5.2.x中修复. Flyway 6.0(将于2019年第一季度到期)将自动更正您的架构历史记录表并进行修复.

That's definitely a bug. Unfortunately this won't be fixed in 5.2.x. Flyway 6.0 (due in Q1 2019) will automatically correct your schema history table and fix this.

或者,如果您真的不想等待,可以手动在架构历史记录表上查找路径,以使此消息消失.

Alternatively if you really don't want to wait, you can manually path up the schema history table to make this message go away.

这篇关于Flyway:如何在不获取"FlywayException:验证失败"的情况下替换不推荐使用的SpringJdbcMigration?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆