Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property to avoid flyway-migrate on startup #44905

Closed
bekoenig opened this issue Mar 26, 2025 · 5 comments
Closed

Add property to avoid flyway-migrate on startup #44905

bekoenig opened this issue Mar 26, 2025 · 5 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@bekoenig
Copy link
Contributor

In addition to automatic migration at application startup, externally controlled migration at runtime is also a relevant scenario. Currently, to prevent migration at application startup, one would have to provide an empty implementation of FlywayMigrationInitializer.

It would be desirable to extend FlywayMigrationInitializer flywayInitializer(...) by @ConditionalOnBooleanProperty(name = "spring.flyway.auto-startup", matchIfMissing = true).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 26, 2025
@wilkinsona
Copy link
Member

Thanks for the suggestion. Can you please expand upon "externally controlled migration at runtime is also a relevant scenario", particularly in terms of how it works with other components that make use of the DataSource and expect its schema to be in place?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Mar 26, 2025
@bekoenig
Copy link
Contributor Author

bekoenig commented Mar 26, 2025

This scenario is relevant to decouple deployment and migrate in zero downtime migrations (see here). The implicit feature flag is the data model change, which will be applied at runtime. The persistence layer has to be compatible to the last and the future database model, which are boundled. At startup time the migrations will not be applied and the persistence layer depends on the last migrated database model. After invoking flyway.migrate() delayed using @Scheduled or remote controlled using JMX or RestController, the database model will be changed.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 26, 2025
@wilkinsona
Copy link
Member

Thanks, @bekoenig.

I wonder how useful an on/off property will be given that Flyway has several different actions that it can perform:

  • baseline
  • clean
  • migrate
  • repair
  • undo
  • validate

By default, Boot calls migrate(). You'd like it not to call anything. As you've noted, this can already be achieved using a FlywayMigrationStrategy bean that also allows more complex logic to be implemented. The question then becomes whether it's worth adding a property that's an alternative to simple custom migration strategies.

For your needs, the property could be set to indicate that no actions should be performed:

spring.flyway.on-startup=do-nothing

It could also accept multiple actions and perform them in order:

spring.flyway.on-startup=clean, migrate

I'll discuss this with the team. In the meantime, please continue to use a custom migration strategy.

@wilkinsona wilkinsona added for: team-meeting An issue we'd like to discuss as a team to make progress and removed status: feedback-provided Feedback has been provided labels Apr 2, 2025
@alihmzyv
Copy link

alihmzyv commented Apr 2, 2025

Hi. @wilkinsona This looks like that it can be a "good first issue". If you agree with me, after deciding with the team, if it is going to developed, could you please consider me as the contributer? I would really be happy to help. Thanks in advance.

@wilkinsona
Copy link
Member

We discussed this today and decided that we don't think it's worth adding a property to control this behavior as the saving vs a custom migration strategy bean is minimal:

@Bean
FlywayMigrationStrategy customMigrationStrategy() {
	return (flyway) -> {};
}

Thanks anyway for the suggestion.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2025
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants