Closed 2019-05-10 closed 2 years ago
Thanks for the report. I'll take a look at it as soon as possible.
Update: works with old 1.6.1 -- I had renamed the migration files since newer flyway has some changes (or even bugs, eg spring.flyway.locations
seems to be ignored/hardcoded to db/callback/
).
Reverting the rename made at least 1.6.1 work again.
I'm just testing it and everything seems to be working fine. Could you please provide a logfile with some details about the error? What version of flyway are you currently using?
There isn't really a log. Just the data isn't there. When logging the SQL queries, those are not the ones from the migration files, but those created by Spring JPA initilaizing the DB.
Flyway version is the one managed by zonky as per Release notes/upgrade:
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-postgres</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<scope>test</scope>
</dependency>
configuration:
spring.flyway.locations=classpath:/db/
spring.flyway.baseline-on-migrate=true
spring.flyway.mixed=true
spring.jpa.properties.hibernate.hbm2ddl.auto=none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
zonky.test.database.type=postgres
zonky.test.database.provider=zonky
migration files:
src/test/resources/db/callback:
afterMigrate__A.sql //data
afterMigrate__B.sql //modifications
afterMigrate__C.sql //modifications
V1.0__.sql //schema
Sorry, I'm not able to reproduce the problem. Could you please provide a reproducer? You can use the following project for this purpose: https://github.com/tomix26/embedded-database-demo. Just fork it and send me your branch.
Still investigating, but so far the key difference seems to be the use of
@SpringBootTest
in my code (required for several reasons)
vs
@DataJpaTest
in your.
Once I use @DataJpaTest
my repositories are populated as with 1.6 -- but it causes new issues, currently for example
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'z.TestZonky': Unsatisfied dependency expressed through field 'myObjectMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.fasterxml.jackson.databind.ObjectMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
So far, I am unable to figure out what exactly the difference is, triggering Zonky to either load or not.
Found the cause.
Since with 1.6.x Flyway migrations triggered twice, I created an empty FlywayMigrationStrategy
@Configuration
public class TestFlywayMigrationStrategyConfig {
@Bean
public FlywayMigrationStrategy flywayMigrationStrategy() {
return flyway -> {
// do nothing
};
}
}
After removing that bean, with 2.1.0 things work as expected.
I still do not fully get why @SpringBootTest
and @DataJpaTest
act differently here, but that's most likely a limitation in my understanding and not a bug.
Glad to hear it, thanks for letting me know.
While at Springboot 2.5.0 things worked perfectly well. Today I updated to 2.5.6 and now tests fail, since the flyway migrations are not executed anymore.
After several hours I got the impression it is somehow to do with the schema already created when starting and not by flyway. Settings
spring.flyway.baseline-on-migrate=true
andspring.jpa.properties.hibernate.hbm2ddl.auto=none
make no difference.Since zonky did not change, but only the Springboot version, it seems to me there's a conflict somewhere.
I tried unsuccessfully with both currently used zonky 1.6.1 and recent 2.1.0.