Flyway cant find migrations in default location when deployed on kura osgi environment

358 views Asked by At

I've work with flyway with most of my project before and never had such issue. I blame osgi. Lets get into details:

I have flyway configured such way:

Flyway flyway = Flyway.configure().locations("classpath:db/migration").dataSource(url, user, password).load();
flyway.migrate();

And its refused to work and I am getting an error:

Flyway Community Edition 6.4.3 by Redgate Unable to resolve location classpath:db/migration. Note this warning will become an error in Flyway 7.

I've checked and I have migration sql files in root of jar file as expected *.jar/db/migration/. But flyway cant find those. Previously I was using OS file path:

Flyway flyway = Flyway.configure().locations("filesystem:/opt/db/migrations").dataSource(url, user, password).load();

Which was working correctly.

My jar is packaged into dp file bundle for osgi platform, and I think it is a problem, as osgi runtime cant find via classpath. I could not find any solution over the network. I found such one: https://github.com/flyway/flyway/issues/1626

which is horror for me. I do not understand why such important feature is labeled with:

Someday-Maybe

I am asking You for any suggestions. Thanks In advance.

1

There are 1 answers

0
Christian Schneider On

If db/migration is in your own bundle then you could try.

Flyway flyway = Flyway.configure(this.getClass().getClassLoader())
  .locations("classpath:db/migration")
  .dataSource(url, user, password).load();
flyway.migrate();

This way you tell the library to use the classloader of your class which is the classloader of your bundle. (At least I hope so. I am not familiar with Flyway, just checked what the API might offer).