I have a project with two modules. Both modules use flyway for migration and initial setup of the database. Both projects are independent. I also have a test in each module. Whenever I run both modules, or also only one test from one module the migration may not be executed.
Module one contains
- a.b.c.account.persistence.jdbc.migrations.Vaccount_1__CreateStructure.java
a.b.c.account.persistence.jdbc.migrations.Vaccount_2__CreateIndexOnName.sql
…
a.b.c.account.persistence.jdbc.migrations.Vaccount_5__AddDAOCreatedAndUpdated.sql
and JDBCAccountPersistenceServiceImpl with JDBCAccountPersistenceServiceImplTest.
Module two contains
- a.b.c.authentication.persistence.jdbc.migrations.Vauth_1__CreateTableForPasswords.sql
a.b.c.authentication.persistence.jdbc.JDBCAuthenticationPersistenceServiceImpl
and JDBCAuthenticationPersistenceServiceImplTest.
Both Impls share a parent class the calls in its init method:
//prepare db.
Flyway flyway = new Flyway();
flyway.setDataSource(getDataSource());
flyway.setLocations(getClass().getPackage().getName()+".migrations");
flyway.migrate();
Both tests work if started separately on clean db and on filled db. However, If I clean DB and run the tests from intellij with running JDBCAuthenticationPersistenceServiceImplTest first, the other test would fail:
org.postgresql.util.PSQLException: ERROR: relation "account" does not exist
Position: 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
The schema_version would in this case contain only one line:
1 | 1 | auth.1 | CreateTableForPasswords | SQL | Vauth_1__CreateTableForPasswords.sql | -1961897674 | another | 2013-01-14 23:39:00.736033 | 18 | t
If i delete all tables manually the test would run again. If I run the test from console on clean db (maven) it also works.
What am I doing wrong?
could it be that auth.1 is considered higher version than account.1 and therefore account.1 patch isn’t executed?
Three issues at hand here.