I’d like my Play app to use different databases for test, local and production (production is Heroku) environments.
In application.conf I have:
db.default.driver=org.postgresql.Driver
%dev.db.default.url="jdbc:postgresql://localhost/foobar"
%test.db.default.url="jdbc:postgresql://localhost/foobar-test"
%prod.db.default.url=${DATABASE_URL}
This doesn’t seem to work. When I run play test or play run,
all DB access fails with:
Configuration error [Missing configuration [db.default.url]] (Configuration.scala:258)
I have a few questions about this:
-
In general, I’m a little confused about how databases are configured
in Play: it looks like there’s plaindb,db.[DBNAME]anddb.and different tutorials make different choices among
[DBNAME].url
those. Certain expressions that seem like they should work (e.g.db.default.url = "jdbc:..."fail with an error that a string was provided where an object was expected). -
I’ve seen other people suggest that I create separate
prod.conf,dev.confandtest.conffiles that each includeapplication.confand then contain DB-specific configuration. But in that case, how do I specify what database to use when I runtestfrom the Play console? -
Is the
%envsyntax supposed to work in Play 2? -
What’s the correct way to specify an environment for
play testto use?
In Play 2 there aren’t different config environments. Instead you just set or override the config parameters in the
conf/application.conffile. One way to do it is on theplaycommand line, like:You can also tell Play to use a different config file:
For an example Procfile for Heroku, see:
https://github.com/jamesward/play2bars/blob/scala-anorm/Procfile
More details in the Play Docs:
http://www.playframework.org/documentation/2.0/Configuration