How to use DATABSE_URL in Play 2.0 (Scala) to connect locally to PostgreSQL 9.1 and Heroku?

I developed the first web application using local PostgreSQL 9.1 on OSX (Lion 10.7.4) using Play! Box 2.0.3. I started by connecting to the database defined in conf / application.conf (relative to the application directory) with

db.default.driver=org.postgresql.Driver db.default.url="jdbc:postgresql://localhost/fotoplay" db.default.user=foo db.default.password=bar 

(username and password were changed before publication). This works for writing and testing. Now I want to deploy to Heroka. I installed Procfile (in the application directory) with a single line:

 web: target/start -Dhttp.port=${PORT} ${JAVA_OPTS} -DapplyEvolutions.default=false -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL 

I exported DATABASE_URL to .bash_profile so that I can send $ DATABASE_URL to the system command line and receive

 postgres://foo: bar@localhost /photoplay 

In Heroku, I created an instance of postgresql. I'm not sure how to write a database evolution to populate a hero, so I turned off this evolution and manually populated my database. My current evolutions create tables and populate them with some source data from some csv files, so I will need to put the csv files somewhere accessible to the hero. At least for the first pass, I don’t want to deal with this problem yet. But as a result of the manual steps, I have a populated database on Heroku.

In this configuration, my application runs correctly locally. However, I am not using DATABASE_URL, which seems to be wrong. I clicked on HEROKU and was unable to connect to the database. Error:

 Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "foo" 

If I remove the username and password, I will break the local configuration. I should use DATABASE_URL instead of the old syntax, but I don't know how to do it. I don’t think I can understand this experimentally (wandering arrogant spaces are hopeless, and there are several possible configuration settings that may be involved and subject to typos). Any directions as to how I should configure application.conf would be appreciated.

+4
source share
1 answer

Worth a try: in your application.conf file, change your db.default.url parameter to include the username and password in the URL, and delete the db.default.user and db.default.password :

 db.default.url="postgres://foo: bar@localhost /fotoplay" 
+6
source

All Articles