Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flyway Java migration not supported in native images #33458

Closed
bclozel opened this issue Dec 5, 2022 · 6 comments
Closed

Flyway Java migration not supported in native images #33458

bclozel opened this issue Dec 5, 2022 · 6 comments
Labels
for: external-project For an external project and not something we can fix status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: bug A general bug

Comments

@bclozel
Copy link
Member

bclozel commented Dec 5, 2022

As discussed on gitter with @jnizet :

Hi team. I was just experimenting with native image support with a small application I have, and I think I found a missing piece in the native support. Flyway migrations are correctly detected and run... except the Java migrations. I get the following warning from Flyway at startup:

WARN 1 --- [ main] o.f.core.internal.command.DbMigrate : Schema "public" has a version (011) that is newer than the latest available migration (010) !

And the reason is that the migration 011, which has been run by a previous run of the application (in "non-native" mode), is a Java migration rather than a more traditional SQL migration (https://flywaydb.org/documentation/tutorials/java)

While we support the discovery of static sql migration files at runtime in a native image (using a custom resolver, org.springframework.boot.autoconfigure.flyway.NativeImageResourceProviderCustomizer) we are currently missing reflection metadata entries for the Java migration classes, since they are instantiated reflectively.

@bclozel bclozel added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Dec 5, 2022
@bclozel bclozel added this to the 3.0.x milestone Dec 5, 2022
@mhalbritter
Copy link
Contributor

mhalbritter commented Dec 5, 2022

I'm not 100% sure that it's enough to register hints for the migration classes. Flyway somehow needs to find them, and classpath scanning in native-image doesn't work like it does on the JVM. We might need to find them at AOT build time and then help flyway find them later in the native image.

@mhalbritter
Copy link
Contributor

@mhalbritter
Copy link
Contributor

mhalbritter commented Dec 5, 2022

You can work around this issue by declaring a bean of type FlywayConfigurationCustomizer and register your Flyway Java migrations manually:

@Component
class JavaMigrationsFlywayCustomizer implements FlywayConfigurationCustomizer {

	@Override
	public void customize(FluentConfiguration configuration) {
		configuration.javaMigrations(new V1__create_table(), new ...);
	}

}

@iTchTheRightSpot

This comment was marked as off-topic.

@wilkinsona

This comment was marked as resolved.

@philwebb philwebb modified the milestones: 3.0.x, 3.1.x Nov 8, 2023
@wilkinsona
Copy link
Member

I don't think we should tackle this one. There's a fairly straightforward workaround (that I've added to the existing Flyway section in the wiki) and I think any further improvements in this area should be made in Flyway itself.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
@wilkinsona wilkinsona removed this from the 3.1.x milestone Apr 22, 2024
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply for: external-project For an external project and not something we can fix labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants