-
Notifications
You must be signed in to change notification settings - Fork 174
Description
Hello,
I tried the new Module Aware Flyway Migration scripts with Spring Modulith 2.0.0-RC1 with spring-modulith-starter-core and spring-modulith-starter-jpa.
When adding flyway scripts in module-specific migration folders db/migration/customer/, db/migration/order etc. and setting spring.modulith.runtime.flyway-enabled=true in the application.properties, the migrations are executed and also the flyway_schema_history is updated correctly, but after executing the migration my Spring process fails anyway:
2025-11-02T17:09:23.835+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] org.flywaydb.core.FlywayExecutor : Database: jdbc:postgresql://127.0.0.1:53345/mydatabase?ApplicationName=hello-spring-modulith-flyway (PostgreSQL 18.0)
2025-11-02T17:09:23.863+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.c.i.s.JdbcTableSchemaHistory : Schema history table "public"."flyway_schema_history" does not exist yet
2025-11-02T17:09:23.865+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbValidate : Successfully validated 4 migrations (execution time 00:00.009s)
2025-11-02T17:09:23.874+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.c.i.s.JdbcTableSchemaHistory : Creating Schema History table "public"."flyway_schema_history" ...
2025-11-02T17:09:23.908+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Current version of schema "public": << Empty Schema >>
2025-11-02T17:09:23.912+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version "0 - add event publications"
2025-11-02T17:09:23.926+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version "1 - add customers"
2025-11-02T17:09:23.936+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version "2 - add orders"
2025-11-02T17:09:23.945+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version "3 - add order items"
------ >>>>>>> 2025-11-02T17:09:23.953+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Successfully applied 4 migrations to schema "public", now at version v3 (execution time 00:00.011s)
2025-11-02T17:09:23.980+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] org.flywaydb.core.FlywayExecutor : Database: jdbc:postgresql://127.0.0.1:53345/mydatabase?ApplicationName=hello-spring-modulith-flyway (PostgreSQL 18.0)
2025-11-02T17:09:23.992+01:00 WARN 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/hibernate/autoconfigure/HibernateJpaConfiguration.class]: Failed to initialize dependency 'flywayInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/flyway/autoconfigure/FlywayAutoConfiguration$FlywayConfiguration.class]: Validate failed: Migrations have failed validation
------ >>>>>>> Detected applied migration not resolved locally: 0.
If you removed this migration intentionally, run repair to mark the migration as deleted.
Need more flexibility with validation rules? Learn more: https://rd.gt/3AbJUZE
2025-11-02T17:09:23.993+01:00 WARN 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.springframework.boot.jdbc.autoconfigure.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2025-11-02T17:09:23.994+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2025-11-02T17:09:24.000+01:00 INFO 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-11-02T17:09:24.006+01:00 ERROR 47120 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/hibernate/autoconfigure/HibernateJpaConfiguration.class]: Failed to initialize dependency 'flywayInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/flyway/autoconfigure/FlywayAutoConfiguration$FlywayConfiguration.class]: Validate failed: Migrations have failed validation
Detected applied migration not resolved locally: 0.
If you removed this migration intentionally, run repair to mark the migration as deleted.
Need more flexibility with validation rules? Learn more: https://rd.gt/3AbJUZE
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-7.0.0-RC2.jar:7.0.0-RC2]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:201) ~[spring-beans-7.0.0-RC2.jar:7.0.0-RC2]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:966) ~[spring-context-7.0.0-RC2.jar:7.0.0-RC2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:620) ~[spring-context-7.0.0-RC2.jar:7.0.0-RC2]
at org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-web-server-4.0.0-RC1.jar:4.0.0-RC1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:765) ~[spring-boot-4.0.0-RC1.jar:4.0.0-RC1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:454) ~[spring-boot-4.0.0-RC1.jar:4.0.0-RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) ~[spring-boot-4.0.0-RC1.jar:4.0.0-RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1374) ~[spring-boot-4.0.0-RC1.jar:4.0.0-RC1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-4.0.0-RC1.jar:4.0.0-RC1]
at nh.demo.hellospringmodulithflyway.HelloSpringModulithFlywayApplication.main(HelloSpringModulithFlywayApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:565) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:52) ~[spring-boot-devtools-4.0.0-RC1.jar:4.0.0-RC1]
. . .
Caused by: org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation
Detected applied migration not resolved locally: 0.
If you removed this migration intentionally, run repair to mark the migration as deleted.
The error also occures when there are no new migrations to be executed:
2025-11-02T16:48:32.565+01:00 INFO 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbValidate : Successfully validated 4 migrations (execution time 00:00.012s)
2025-11-02T16:48:32.588+01:00 INFO 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Current version of schema "public": 3
2025-11-02T16:48:32.590+01:00 INFO 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.f.core.internal.command.DbMigrate : Schema "public" is up to date. No migration necessary.
2025-11-02T16:48:32.618+01:00 INFO 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] org.flywaydb.core.FlywayExecutor : Database: jdbc:postgresql://127.0.0.1:52968/mydatabase?ApplicationName=hello-spring-modulith-flyway (PostgreSQL 18.0)
2025-11-02T16:48:32.631+01:00 WARN 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/hibernate/autoconfigure/HibernateJpaConfiguration.class]: Failed to initialize dependency 'flywayInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/flyway/autoconfigure/FlywayAutoConfiguration$FlywayConfiguration.class]: Validate failed: Migrations have failed validation
Detected applied migration not resolved locally: 0.
If you removed this migration intentionally, run repair to mark the migration as deleted.
Need more flexibility with validation rules? Learn more: https://rd.gt/3AbJUZE
2025-11-02T16:48:32.632+01:00 WARN 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.springframework.boot.jdbc.autoconfigure.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2025-11-02T16:48:32.633+01:00 INFO 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2025-11-02T16:48:32.639+01:00 INFO 46093 --- [hello-spring-modulith-flyway] [ restartedMain] [ ] .s.b.a.l.ConditionEvaluationReportLogger :
When I add all migration files into one single folder (db/migration) it works fine, even when spring.modulith.runtime.flyway-enabled=true.
You can find my sample project, that shows the problem, here: https://github.com/nilshartmann/hello-spring-modulith-flyway.
I created that project with Spring Initializer and only added the migration scripts, the module folders and adjusted the application.properties file.
When running the (default) HelloSpringModulithFlywayApplicationTests test class, the application is not able to start. Also running the main application class HelloSpringModulithFlywayApplication does not work.
Not sure, what I'm doing wrong here.