postgresqlscalaplayframework-2.6playframework-evolutions

Play 2.6 evolutions DB change not applied


My project was recently updated from Play 2.5 to 2.6.13. I added a new script 16.sql but the change were not applied in the table play_evolutions

According to the documentation 2.6, the EvolutionsComponents have to be injected if you use compile time DI. But Guice is runtime DI, so I should not have to inject any components.

I enabled the evolutions in the build.sbt

libraryDependencies ++= Seq(evolutions, jdbc)

In application.conf

play.evolutions.enabled=true
play.evolutions.autoApply=true

What is my project missing ? Any git examples are welcome


Solution

  • I solved it by following the documentation since upgrading to Play 2.6

    Here is my code

    import play.api.ApplicationLoader.Context
    import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
    import play.api.db.{DBComponents, HikariCPComponents}
    import play.api.db.evolutions.EvolutionsComponents
    import play.api.routing.Router
    import play.filters.HttpFiltersComponents
    import router.Routes
    
    class MyApplicationLoader extends ApplicationLoader {
    
      def load(context: ApplicationLoader.Context): Application = {
        new AppComponents(context).application
      }
    }
    
    class AppComponents(context: Context)
        extends BuiltInComponentsFromContext(context)
        with DBComponents
        with EvolutionsComponents
        with HikariCPComponents
        with HttpFiltersComponents {
      // this will actually run the database migrations on startup
      applicationEvolutions
    
      //  val prefix: String = "/"
      lazy val router = Router.empty
      //  lazy val router: Router = bind(classOf[Routes]).to(classOf[Routes])
    
    }
    

    And in the conf/application.conf, add this line

    play.application.loader=MyApplicationLoader