flyway / flyway-play

Play modules for Flyway
Other
168 stars 40 forks source link

How to do Flyway migrations eager in Play Framework #89

Open pme123 opened 4 years ago

pme123 commented 4 years ago

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 commented 1 year ago

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

pme123 commented 1 year ago

No, sorry

nemoo commented 1 month ago

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 commented 1 month ago

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. :point_up: instead of the orginal flyway-play module, something like play.modules.enabled += "my.org.flywaydb.PlayModule"