How to connect to PostgreSQL in Heroku with Luminus?

370 views Asked by At

I just created a Luminus app and it has two separate places where database access is defined. In project.clj for ragtime:

:ragtime {:migrations ragtime.sql.files/migrations
          :database "jdbc:postgresql://localhost/foobar?user=db_user_name_here&password=db_user_password_here"}

and in src/foobar/db/core.clj:

(def db-spec
  {:subprotocol "postgresql"
   :subname "//localhost/foobar"
   :user "db_user_name_here"
   :password "db_user_password_here"})

Has anybody ever wrote code to break down the DATABASE_URL Heroku provides, or somehow use it for the connection? Surely I'm not the first one to want to do this, right?

Also, in the process, it would be nice to have separate credentials for development and production.

1

There are 1 answers

0
codefinger On

If ragtime is using clojure.java.jdbc (I believe it is), then you should be able to pass the DATABASE_URL to it directly. A bit like:

(def spec (or (System/getenv "DATABASE_URL") "postgresql://localhost:5432/shouter"))

For more examples, see the Heroku Dev Center and Getting Started guides.