weavejester / ragtime

Database-independent migration library
Eclipse Public License 1.0
608 stars 85 forks source link

Issues with Ragtime and Heroku #46

Closed kouphax closed 9 years ago

kouphax commented 9 years ago

I've recently started a new project (Luminus based, nothing added) and added ragtime 0.3.7 to perform migrations. This worked (past tense see later) locally as expected however when I deploy to Heroku and run heroku run "lein ragtime migrate" it fails with the following error,

Exception in thread "main" java.lang.RuntimeException: No such var: sql/with-connection, compiling:(ragtime/sql/database.clj:22:3)

I suspect this is related to #23 but I haven't been able to find a solution. In a bid to diagnose the issue locally I blew away my ~/.m2 directory and ran the command locally and now I'm getting the same issue.

UPDATE It seems I can workaround the issue both locally and on heroku by issuing

lein do clean, ragtime migrate

However I'm not sure if this is just covering up a dependency problem so thought it worth mentioning.

laser commented 9 years ago

I'm also getting this error when running ragtime migrations on Heroku.

My project.config looks like this:

(defproject tutorial "0.1.0-SNAPSHOT"
  :dependencies [[compojure "1.2.2"]
                 [environ "1.0.0"]
                 [yesql "0.4.0"]
                 [org.clojure/clojure "1.6.0"]
                 [ragtime/ragtime.sql.files "0.3.8"]
                 [ring/ring-defaults "0.1.2"]
                 [ring/ring-jetty-adapter "1.3.2"]
                 [ring/ring-json "0.3.1"]]

  :min-lein-version "2.0.0"

  :plugins [[ragtime/ragtime.lein "0.3.8"]
            [lein-ring "0.8.13" :exclusions [org.clojure/clojure]]
            [lein-environ "1.0.0"]]

  :profiles {
             :shared {:ragtime {:migrations ragtime.sql.files/migrations}}
             :production [:shared {:dependencies [[mysql/mysql-connector-java "5.1.6"]]
                                   :ragtime {:database (let [prefix "jdbc:"]
                                                         (System/getenv "DATABASE_URL"))}}]}

  :ring {:handler tutorial.handler/app}

  :source-paths ["src" "db"])

Full log output from Heroku:

23:17 $ heroku run 'lein ragtime migrate'
Running `lein ragtime migrate` attached to terminal... up, run.1302
Picked up JAVA_TOOL_OPTIONS: -Xmx384m  -Djava.rmi.server.useCodebaseOnly=true
Retrieving org/clojure/tools.nrepl/0.2.6/tools.nrepl-0.2.6.pom from central
Retrieving clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.pom from clojars
Retrieving org/clojure/tools.nrepl/0.2.6/tools.nrepl-0.2.6.jar from central
Retrieving clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.jar from clojars
Picked up JAVA_TOOL_OPTIONS: -Xmx384m  -Djava.rmi.server.useCodebaseOnly=true
Exception in thread "main" java.lang.RuntimeException: No such var: sql/with-connection, compiling:(ragtime/sql/database.clj:22:3)
    at clojure.lang.Compiler.analyze(Compiler.java:6464)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3665)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
    at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
    at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6632)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.access$100(Compiler.java:38)
    at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:538)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler.eval(Compiler.java:6707)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    at clojure.lang.RT.loadResourceScript(RT.java:370)
    at clojure.lang.RT.loadResourceScript(RT.java:361)
    at clojure.lang.RT.load(RT.java:440)
    at clojure.lang.RT.load(RT.java:411)
    at clojure.core$load$fn__5066.invoke(core.clj:5641)
    at clojure.core$load.doInvoke(core.clj:5640)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5446)
    at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
    at clojure.core$load_lib.doInvoke(core.clj:5485)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:626)
    at clojure.core$load_libs.doInvoke(core.clj:5524)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:626)
    at clojure.core$require.doInvoke(core.clj:5607)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at ragtime.main$_main.doInvoke(main.clj:65)
    at clojure.lang.RestFn.invoke(RestFn.java:551)
    at clojure.lang.Var.invoke(Var.java:419)
    at user$eval5.invoke(form-init5713149402295730638.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6703)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    at clojure.lang.Compiler.loadFile(Compiler.java:7086)
    at clojure.main$load_script.invoke(main.clj:274)
    at clojure.main$init_opt.invoke(main.clj:279)
    at clojure.main$initialize.invoke(main.clj:307)
    at clojure.main$null_opt.invoke(main.clj:342)
    at clojure.main$main.doInvoke(main.clj:420)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: No such var: sql/with-connection
    at clojure.lang.Util.runtimeException(Util.java:221)
    at clojure.lang.Compiler.resolveIn(Compiler.java:6914)
    at clojure.lang.Compiler.resolve(Compiler.java:6884)
    at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6845)
    at clojure.lang.Compiler.analyze(Compiler.java:6427)
    ... 54 more
michaelklishin commented 9 years ago

Can it be dependency/buildpack cache on Heroku?

kouphax commented 9 years ago

I can reproduce the issue when I wipe my local cache on my local machine so I don't think it's Heroku specific

upgradingdave commented 9 years ago

fwiw, I just ran into this same stack trace using ragtime on a local luminus project (I'm not using anything related to heroku).

I can reproduce consistently by first doing:

lein uberjar

and then

lein ragtime migrate

If I do a lein do clean, ragtime migrate, then I don't see the error.

The project was generated using the luminus lein template with http-kit and postgres profiles. And I also added pallet to manage deployments.

mll commented 9 years ago

Hi! I have exactly the same issue on heroku, but unfortunately 'lein do clean, ragtime migrate' doesn't help in my case. I need to deploy and cannot migrate at all! Help!!!

mll commented 9 years ago

Ok, so I seem to know what is going on. It seems that there's a problem on maven repo with [org.clojure/java.jdbc "0.3.6"]

Add [org.clojure/java.jdbc "0.3.7"] to your project.clj's :requirements section. This solved the issue for me.

weavejester commented 9 years ago

Should be fixed in Ragtime 0.4.0 and above.