Leiningen Integration

Jonas De Taeye edited this page Aug 19, 2015 · 2 revisions

Migrations can be run through Leiningen by taking advantage of aliases and the "run" task.

First, choose a namespace and add a function to load a configuration. In the example below, the user namespace is used:

(ns user
  (:require [ragtime.jdbc :as jdbc]
            [ragtime.repl :as repl]))

(defn load-config []
  {:datastore  (jdbc/sql-database "jdbc:h2:file:example.h2")
   :migrations (jdbc/load-resources "migrations")})

Then use the configuration to make zero-argument migrate and rollback functions:

(defn migrate []
  (repl/migrate (load-config)))

(defn rollback []
  (repl/rollback (load-config)))

These can be used at the REPL, and at the command line by placing the following Leiningen aliases in your project file:

:aliases {"migrate"  ["run" "-m" "user/migrate"]
          "rollback" ["run" "-m" "user/rollback"]}

Running lein migrate will now migrate the database to the latest version, and lein rollback will roll the database back one version.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.