Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.42 KB | None | 0 0
  1. package app
  2.  
  3. import com.google.inject.Guice
  4. import play.api.i18n.{Lang, Messages}
  5. import play.api.mvc.Results._
  6. import play.api.mvc.{RequestHeader, Result}
  7. import play.api._
  8. import play.api.mvc._
  9. import play.api.libs.concurrent.Execution.Implicits.defaultContext
  10. import play.api.Logger
  11. import play.api.Play
  12. import play.api.Play.current
  13. import play.api.db.DB
  14. import com.googlecode.flyway.core.Flyway
  15.  
  16. /**
  17.  * The global configuration.
  18.  */
  19. object Global extends GlobalSettings {
  20.  
  21.   override def onStart(app: Application) {
  22.     Logger.info("Application onStart starting")
  23.  
  24.     // run database migrations
  25.     runDatabaseMigrations("default")
  26.  
  27.     Logger.info("Application onStart finished")
  28.   }
  29.  
  30.   def runDatabaseMigrations(dbName: String) = {
  31.     Logger.info("Database migrations starting")
  32.     val migrationFilesLocation = s"db/migration/${dbName}"
  33.     Play.current.resource(migrationFilesLocation) match {
  34.       case Some(r) => {
  35.         Logger.info(s"Directory for migration files found: ${migrationFilesLocation}")
  36.  
  37.         val flyway = new Flyway
  38.         flyway.setDataSource(DB.getDataSource(dbName))
  39.         flyway.setLocations(migrationFilesLocation)
  40.         flyway.setInitOnMigrate(true)
  41.         flyway.migrate()
  42.       }
  43.       case None => {
  44.         Logger.warn(s"Directory for migration files not found: ${migrationFilesLocation}")
  45.       }
  46.     }
  47.     Logger.info("Database migrations finished")
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement