Search code examples
clojureleiningencompojureheroku-postgres

Ragtime Migrate with Environment Variables throwing Error (Heroku Deployment)


I'm trying to run lein ragtime migrate on a heroku dyno. Normally, I would set the database path in my project.clj like so:

(defproject my-project "0.1.0-SNAPSHOT"
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/java.jdbc "0.3.7"]
                 [postgresql "9.3-1102.jdbc41"]
                 [ragtime "0.3.9"]
                 [ring "1.4.0-RC1"]
                 [ring/ring-defaults "0.1.2"]]
  :plugins [[lein-ring "0.8.13"]
            [ragtime/ragtime.lein "0.3.9"]]
   ...
  :ragtime {:migrations ragtime.sql.files/migrations
            :database (System/getenv "DATABASE_URL")}
   ...

  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring-mock "0.1.5"]]
   :test {:ragtime {:database (System/getenv "DATABASE_URL")}}})

When I run the command, I get the following error both locally and depolying over Heroku

java.lang.IllegalArgumentException: No method in multimethod 'connection' for dispatch value: postgres

Any pointers in the right direction would be very appreciated.


Solution

  • Ragtime 0.3.9 uses the scheme from the connection url as the dispatch value for the connection multimethod. The code is here and here. But the DATABASE_ENV from heroku doesn't have a "jdbc" but a "postgres" scheme (which makes sense, it has to be generic).

    A workaround could be to add the "jdbc://" prefix:

    :ragtime {:migrations ragtime.sql.files/migrations
              :database ~(str "jdbc://" (System/getenv "DATABASE_URL"))}
    

    You can also upgrade to [ragtime "0.4.0"] which doesn't use the scheme to find out how to create the connection. See the wiki for info about the upgrade path from 0.3.x