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

How to do Flyway migrations eager in Play Framework #89

Open
pme123 opened this issue Feb 20, 2020 · 4 comments
Open

How to do Flyway migrations eager in Play Framework #89

pme123 opened this issue Feb 20, 2020 · 4 comments

Comments

@pme123
Copy link

pme123 commented Feb 20, 2020

What I want to do is to run the migration eagerly before other Components need the database.

I tried to inject the FlywayPlayComponents into my Setup, like:

    @Singleton
    class AppSetup @Inject()(val environment: Environment,
                                val webCommands: WebCommands,
                                val configuration: Configuration,
                           )
      extends FlywayPlayComponents {
    
      flywayPlayInitializer
      ...

But AppSetup is still run first and the Flyway migration is run with the first request.

Is there a way to do this or do I miss something?

I also created a Stackoverflow question:

https://stackoverflow.com/questions/60303933/how-to-do-flyway-migrations-eager-in-play-framework

@hertg
Copy link

hertg commented Dec 13, 2022

Were you able to solve it? I have the same issue.

@pme123
Copy link
Author

pme123 commented Dec 13, 2022

No, sorry

@nemoo
Copy link

nemoo commented May 21, 2024

I don't understand. Isn't this a show-stopper? What is the whole point of flyway-play if it cannot perform the migrations?

@mkurz
Copy link
Member

mkurz commented May 22, 2024

I am not maintaining this project, just want to add my comment:
Currently there is no way to eagerly run flyway migrations in DEV mode, since this is by design of the this project to run migrations only when requests come in (again, in dev mode), see this line here.

You could try to:

  1. copy PlayInitializer.scala and modify it so also in dev mode flyways.migrate(dbName) (or flyways.checkState(dbName) ?) gets executed.
  2. to make this work you then need to copy PlayModule.scala and bind you just copied PlayInitializer now (line 23)
  3. In your application.conf you then need to enable your custom module from 2. ☝️ instead of the orginal flyway-play module, something like play.modules.enabled += "my.org.flywaydb.PlayModule"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants