How to upgrade from flyway 5.2.4 to 9.0.1?
Asked Answered
A

1

5

I have spring boot 2.7.0 maven project that uses flyway 5.2.4. I need to upgrade flyway to newer version.

It all started because I needed to update h2 and h2gis-functions so that I could use h2 1.4.200 or newer due to new features that I needed from h2 v 1.4.200. I currently had com.h2database:h2:1.4.197 and org.orbisgis:h2gis-functions:1.3.2 dependencies in my pom.xml. Those 2 need to be compatible with each other. As I understood not all versions are compatible. So I decided to try if com.h2database:h2:2.1.214 and org.orbisgis:h2gis:2.1.0 work or not

After doing it I started to get error that I previously did not get:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT [*]VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME = 'info.BUILD_ID'"; expected "DISTINCT, ALL, *, INTERSECTS (, NOT, EXISTS, UNIQUE, INTERSECTS"; SQL statement: SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME = 'info.BUILD_ID' [42001-214]

Which I learned was caused by old flyway. In my project in pom.xml I have flyway 5.2.4. After googling the issue I ran into this stackoverflow post: H2 version change issue from 1.4.200 to 2.0.202?

Which has similar error (Couldn't find exact same error). There it was suggested that poster should upgrade flyway to 8.2.2 or any newer version. I am not exactly sure if I necessarily need flyway 9.0.1 or if any older version is also fine but looks like I need some newer version of flyway.

After updating flyway version to 9.0.1 and try to run tests the application does not start anymore.

The error I get is:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: org.flywaydb.core.api.configuration.FluentConfiguration.ignoreMissingMigrations(Z)Lorg/flywaydb/core/api/configuration/FluentConfiguration;
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330)
    ... 207 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: org.flywaydb.core.api.configuration.FluentConfiguration.ignoreMissingMigrations(Z)Lorg/flywaydb/core/api/configuration/FluentConfiguration;
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    ... 219 more
Caused by: java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: org.flywaydb.core.api.configuration.FluentConfiguration.ignoreMissingMigrations(Z)Lorg/flywaydb/core/api/configuration/FluentConfiguration;
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.configureIgnoredMigrations(FlywayAutoConfiguration.java:264)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.configureProperties(FlywayAutoConfiguration.java:205)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 220 more
Caused by: java.lang.NoSuchMethodError: org.flywaydb.core.api.configuration.FluentConfiguration.ignoreMissingMigrations(Z)Lorg/flywaydb/core/api/configuration/FluentConfiguration;
    at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
    at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975)
    at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000)
    at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1394)
    at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1750)
    at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477)
    ... 228 more

How to fix NoSuchMethodError?

Afeard answered 21/7, 2022 at 15:28 Comment(0)
A
9

This error comes up because method ignoreMissingMigrations was deprecated in Flyway 8.x and removed in Flyway 9.x. See this: https://github.com/flyway/flyway/issues/3484

Because even the latest Spring Boot (2.7.2 as of now) still uses ignoreMissingMigrations in FlywayAutoConfiguration class the only ways to solve this are either:

  • Use Flyway 8.x
  • Disable Spring FlywayAutoConfiguration and use manually written FlywayConfiguration to configure Flyway while using Flyway 9.x
Alboin answered 23/7, 2022 at 4:4 Comment(7)
Tnx! With FW 8.2.2 I started to get org.flywaydb.core.api.FlywayException: Unable to calculate checksum of V5_57__file_name.sql Input length = 1 That file worked with old FW 5.2.4. The sql file itself is just a normal insert statement with some TO_CLOB('blah blah blah')s in it. That TO_CLOB contains some finnish/swedish letters such as ä, å, ö. Coud that be a problem? Further down it is caused by MalformedInputException: Input length = 1 It does not say exactly where in the file problem is.Afeard
@Afeard Yes, that's most probably the case. They have modified slightly checksum calculation in 6.x: github.com/flyway/flyway/issues/2744#issuecomment-607339091 See the issue details: github.com/flyway/flyway/issues/2744 Most probably this: github.com/flyway/flyway/issues/2744#issuecomment-620075048 is your caseAlboin
Thanks! I noticed that post myself too. But It says "I guess the simplest workaround is to expand ä into ae". In my case it's not really an option because those migrations end up in production where we need to deal with real ä not ae. And since it would mean having to go back to hack already applied migrations in live env then I dont think I get approval for this solution. I guess it's a "won't fix" on their side as it's been already since 2020 and it's 2022 now?Afeard
Not necessarily, you can use flyway repair to recompute checksums: - flywaydb.org/documentation/command/repair Similar case here, where they used repair to fix it: github.com/flyway/flyway/issues/2474#issuecomment-522962377Alboin
Could you provide an example on disabling the FlywayAutoConfiguration and how to manually configure it?Yamamoto
@swordgit: You would need to copy-paste Spring-Boot auto configuration into your config folder - it will override Springs' config and tweak it according (as you can't really extend it because all interesting stuff is private). Here is an example: github.com/valb3r/flyway_9_spring_2_7_2-issueAlboin
Thank. I fixed it by setting on build.gradle: implementation 'org.flywaydb:flyway-core:8.5.12'Tsingyuan

© 2022 - 2024 — McMap. All rights reserved.