I want to use Flyway (flyway-play) to do db migrations.
I have absolutely no problems connecting to the database with Slick, making queries and inserting new data etc. However, I can not get Flyway to work with it.
When I visit http://localhost:9000/@flyway/postgres
endpoint I get database postgres not found
. And in fact on http://localhost:9000/@flyway
I can see that there are no databases detected.
I have prepared migrations and placed them in the conf\db\migration\postgres
folder.
This is my configuration for the postgres
database:
slick {
dbs {
postgres {
driver = "slick.driver.PostgresDriver$"
db {
profile = org.postgresql.Driver
url = "jdbc:postgresql://localhost:5432/"${db-name}
user = ${db-user}
password = ${db-password}
connectionPool = disabled
keepAliveConnection = true
autoCommit = false
}
}
}
}
And my DatabaseProvider
:
package database.config
import javax.inject.{Inject, Singleton}
import play.api.db.slick.DatabaseConfigProvider
import play.db.NamedDatabase
import slick.jdbc.{JdbcProfile, PostgresProfile}
@Singleton
final class DatabaseProvider @Inject()(@NamedDatabase("postgres") configProvider: DatabaseConfigProvider) {
val dbConfig = configProvider.get[PostgresProfile]
}
@vdebergue thanks for pointing in the right direction, I got it to work.
I moved my my migrations into conf\db\migration\default
folder and tweaked application.conf
a little so it looks like this:
db {
default = ${slick.dbs.postgres.db}
default.migration.locations=["common","postgres"]
}
slick {
dbs {
postgres {
driver = "slick.driver.PostgresDriver$"
db {
profile = org.postgresql.Driver
driver = ${slick.dbs.postgres.db.profile} // required for Flyway
url = "jdbc:postgresql://localhost:5432/"${db-name}
user = ${db-user}
password = ${db-password}
connectionPool = disabled
keepAliveConnection = true
autoCommit = false
}
}
}
}