Skip to content

Per module Flyway execution should not run for modules that have no migration scripts/have no persistent types #1684

@MartinAhrer

Description

@MartinAhrer

I have a project with ~20 modules, of which some represent just infrastructure or contain types that are being used by other modules. These define no persistent types and require no Flyway migration. When running Flyway with per-module migration scripts, this turns out to be really slow, as Flyway is creating the history table and checking for migration scripts when there is really nothing to do.

Eventually modulith runtime could check if

  • a module has migration scripts a
  • a module has entities

and only then invoke the flyway migration.

I looked into tweaking SpringModulithFlywayAutoConfiguration

@AutoConfiguration
@ConditionalOnClass({ Flyway.class, FlywayMigrationStrategy.class })
static class SpringModulithFlywayAutoConfiguration {

	@Bean
	@ConditionalOnProperty(name = "spring.modulith.runtime.flyway-enabled", havingValue = "true")
	SpringModulithFlywayMigrationStrategy springModulithFlywayMigrationStrategy(
			ApplicationModuleIdentifiers identifiers, BeanFactory factory) {

		var filter = new ModuleFilter(factory);
		var filtered = ApplicationModuleIdentifiers.of(identifiers.stream().filter(filter).toList());

		return new SpringModulithFlywayMigrationStrategy(filtered);
	}
}

However, as ModuleFilter is not a public API, it's a bit difficult to replace the springModulithFlywayMigrationStrategy bean with a custom one.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions