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 plain db
, db.[DBNAME]
and db.
[DBNAME].url
and different tutorials make different choices among
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.conf
and test.conf
files that each include application.conf
and then contain DB-specific configuration. But in that case, how do I specify what database to use when I run test
from the Play console?
Is the %env
syntax supposed to work in Play 2?
What's the correct way to specify an environment for play test
to use?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…