4

By design the flyway migrations run in transactions and synchronously pretty early during startup of an application. This is usually desired, to ensure before business logic starts to execute the database is in a consistent state (migrated) or the migration fails and the app crashes.

In some cases I'd really like to be able to start the application without it waiting for some migrations to be completed (long running migrations, creating indexes or materialized views, etc.). This might also be needed when deploying from a CI-Server and using deploy-timeouts / health-checks (that can not be raised indefinitely) to ensure the deployment worked as expected.

Is there any configuration / convention / best practice to enable async migrations?
(i.e. naming the migration A2_00__UpdateSthLong.sql instead of V2 (standard) or R2 (Repeatable migration).

icyerasor
  • 4,973
  • 1
  • 43
  • 52

1 Answers1

2

Seems like its not possible (yet):

  • There is an issue requesting this on github: https://github.com/flyway/flyway/issues/950

  • Flyway for micronaut, seems to already support this: https://github.com/flyway/flyway/issues/950

  • A temp solution until support is integrated could be to use Java Migrations and spawn an async-Task from within the migrate method yourself. The migration wouldn't be transactional then of course :(

  • Another solution might be to do the migration before actually starting up the application (i.e. by using the maven task).

icyerasor
  • 4,973
  • 1
  • 43
  • 52
  • How would you spawn an async-task within the migrate method without loosing the database connection? – cnmuc Apr 06 '23 at 09:22
  • Hmmn I never tried to actually do it that way. You probably can't pass the context and can't yet use any kind of dependency injection, but instead you'd have to open a (jdbc) connection bare bones and execute the statements..? – icyerasor Apr 07 '23 at 10:11