I implemented Flyway in a number of applications I support and it worked like a dream.
However as soon as I deployed the applications to the test environment the migrations stopped working.
After some investigation I found that the migrations are not being located by Flyway when they are loaded into a jar file, but when they are not zipped up (like when I am working in Eclipse or if I extract the jar into the classpath) it works as expected.
Due to the plugin architecture of the applications I am not in a position to use the "default" setting and as such am setting the Flyway object up like this:
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setBaseDir("za/co/company/application/plugin1/db/migration");
flyway.setTable(tableName);
flyway.setBasePackage("za.co.company.application.plugin1.db.migration");
flyway.init();
flyway.migrate();
If one was to unzip the jar file the sql files would be located in: za/co/company/application/db/migration
As mentioned I know the migrations work, just not when they are in the jar file. The code above executes perfectly, it's just that there are no sql files found to run as part of the migration.
Although originaly developed using flyway-core-1.6 I have tried it (with the same negative results) with 1.6.1 and a 1.7_SNAPSHOT release I found here and here where a similar problem was reported.
EDIT: additional info
OS: Windows XP
JDK: 1.7.0_04
DB: SQL Server 2005
Running straight from the command window via a bat file.
2012-06-27 15:50:05.855 main: flyway.migrate()
2012-06-27 15:50:05.886 Database: Microsoft SQL Server
2012-06-27 15:50:05.902 Schema: dbo
2012-06-27 15:50:05.902 Unable to find path for sql migrations: za\co\company\application\plugin1\db\migration
2012-06-27 15:50:05.918 Scanning URL: jar:file:/C:/Temp/lib/plugin1.jar!/za/co/company/application/plugin1/db/migration
2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/ (filename: )
2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/V1_1__Allows_cancelations.sql (filename: V1_1__Allows_cancelations.sql)
2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/V1__Base_version.sql (filename: V1__Base_version.sql)
2012-06-27 15:50:05.933 main: done Migrate.
I have confirmed that I am using the default prefix (V) and suffix (.sql). And the names of the migration files mentioned in the log as being filtered out are indeed the migrations I would like to have performed.
EDIT: Still more info. I cloned the source repository and got a stack trace just before the resource was logged as being filtered out.
at com.googlecode.flyway.core.util.scanner.ClassPathScanner.filterResourceNames(ClassPathScanner.java:203)
at com.googlecode.flyway.core.util.scanner.ClassPathScanner.findResourceNames(ClassPathScanner.java:136)
at com.googlecode.flyway.core.util.scanner.ClassPathScanner.scanForClasses(ClassPathScanner.java:67)
at com.googlecode.flyway.core.migration.jdbc.JdbcMigrationResolver.resolveMigrations(JdbcMigrationResolver.java:51)
at com.googlecode.flyway.core.migration.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:175)
at com.googlecode.flyway.core.migration.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:156)
at com.googlecode.flyway.core.migration.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:119)
at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:565)
at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:1)
at com.googlecode.flyway.core.Flyway.execute(Flyway.java:850)
at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:561)
I have confirmed that the ONLY time the migrations are filtered out is when it finds them in a jar file. It is as if .sql migrations are not even scanned for when they re inside a jar file.
I am still poking around and will update accordingly.
EDIT: Source Code query: I am not overly familiar with the Flyway source code I have been poking around in it for only a few hours...
What does this piece of code in the resolveMigrations method of the SqlMigrationResolver class supposed to do? If I remove it from the code the SQLmigrations load perfectly from the Jar file, if not they don't load and the warning is logged.
if (StringUtils.hasText(normalizedBaseDir)) && !new ClassPathResource(normalizedBaseDir + "/").exists() ) {
LOG.warn("Unable to find path for sql migrations: " + location);
return migrations;
}
Try the newly released 1.7. The offending statement has been removed.