spring-native icon indicating copy to clipboard operation
spring-native copied to clipboard

Flyway Support

Open goafabric opened this issue 3 years ago • 10 comments

Hello, i tried to get flyway up and running with spring native. Which is a very important library for us, because it's basically used for every JPA related projected. So I am wondering, way nobody else already raised an issue.

The problem is, that flyway is not capable of reading the migration scripts:

... Flyway failed to initialize: none of the following migration scripts locations could be found: - classpath:db/migration ...

I also tried to have the migration scripts inside the filesystem, at least for a workaround, but this also did not work

... caused by: java.lang.NullPointerException: null at org.flywaydb.core.internal.util.FileCopyUtils.copy(FileCopyUtils.java:124) ~[na:na] at org.flywaydb.core.internal.util.FileCopyUtils.copyToString(FileCopyUtils.java:84) ~[na:na] at org.flywaydb.core.internal.license.VersionPrinter.readVersion(VersionPrinter.java:121) ~[na:na] ...

So flyway seems to have some trouble to read files either from the classpath or FS.

Libraries:

  • Spring Boot 2.4.4
  • Spring Native 0.9.2
  • Flyway 7.1.1 (managed by spring boot dependencies)

goafabric avatar May 13 '21 11:05 goafabric

There is an old issue that explains how it was solved for quarkus: https://github.com/micronaut-projects/micronaut-flyway/issues/12

goafabric avatar May 13 '21 12:05 goafabric

For documentation purposes - I created a PR that was rejected and closed for various reasons. If someone wants to create a PR again, it may make sense to take a quick look at it.

cschaible avatar Nov 16 '21 07:11 cschaible

When will this feature be supported ? thanks

dudiao avatar Mar 18 '22 16:03 dudiao

@cschaible thank u for the amazin work that you have done here .. and it's said that the PR was rejected i tried to get it running by basically just adding the classes to my local project. But no matter what i do, the build will complain about BufferLogCreator beeing accessed during build time. Even if i explictly set it to Initialization at Runtime. This using the latest Versions of Spring / Native. Do you have an idea ? https://github.com/goafabric/person-service/actions/runs/2502215038

goafabric avatar Jun 17 '22 10:06 goafabric

@goafabric The BufferLogCreator issue can be solved by replacing Flyway's LogFactory and Log classes in FlywayFeatureand NativePathLocationScanner with LoggerFactory from slf4j.

The InitializationHint for the NativePathLocationScanner in the Application class isn't recognized. Therefore I've added the configuration to the buildArgs in build.gradle.kts.

If you use MariaDB you have to add additional hints.

You can see all the adjustments I made to get it running with Spring Boot 2.7.0 here.

I'm not 100% sure how the plugin configuration has to be translated to Maven but I hope this helps.

cschaible avatar Jun 17 '22 20:06 cschaible

@cschaible thank you very much .. will retry [edit] after a while got it working, thx again .. but this stuff really needs to go somewhere graalvm or spring boot i watched the spring native video from spring i/o where they also announced that there are plans about graalvm repo contributions .. but afaik nothing has surfaced since

goafabric avatar Jun 18 '22 06:06 goafabric

@cschaible the latest spring native 0.12.1 breaks the progress for flyway, the dreaded BufferedLogCreator Problem returns the changelog mentions a change for InitializationHints ... already tried a bunch of different stuff, but can't get it working with that version

do you have an idea ?

goafabric avatar Jul 16 '22 11:07 goafabric

@goafabric Currently I have no idea, how to solve the problem. My attempts have also failed. At the moment I don't have enough time to look into it in more detail. I think you have to wait until someone with more experience solves the implementation properly and hopefully finally. I could imagine that there will be some progress near the Spring Boot 3.0 release later this year.

cschaible avatar Jul 19 '22 19:07 cschaible

@cschaible ok thank you .. and for taking a look

goafabric avatar Jul 20 '22 05:07 goafabric

@cschaible Together with Boot 2.7.2 i was able to get it working again .. don't know if this is a coincidence or not ... Simply by adding the demanded hint. Its now also possible to finally scrap the command line parameter ...

@NativeHint(trigger = org.flywaydb.core.Flyway.class, initialization = {@InitializationHint(types = {org.flywaydb.core.internal.util.FeatureDetector.class, NativePathLocationScanner.class, org.flywaydb.core.internal.logging.buffered.BufferedLogCreator.class}, initTime = InitializationTime.BUILD)},

goafabric avatar Jul 22 '22 09:07 goafabric

@sdeleuze @snicoll Flyway is now working perfectly fine with Spring Boot 3.0 RC1 So I will close this issue. Thank u and the team for the great efforts in 3.0 RC1

goafabric avatar Oct 22 '22 11:10 goafabric