A component for the Ragtime migration library, designed to be used in the Duct framework (but can be used in any component-based system).
Add the following dependency to your project.clj
:
[duct/ragtime-component "0.1.4"]
Start by requiring the library and the Component library:
(require '[duct.component.ragtime :refer [ragtime migrate rollback]]
'[com.stuartsierra.component :as component])
You will also need a database component that contains a :spec
key. In this example, we'll just use a map:
(def system
(-> (component/system-map
:db {:spec {:connection-uri "jdbc:h2:mem:test"}}
:ragtime (ragtime {:resource-path "migrations"}))
(component/system-using
{:ragtime [:db]})))
When we start the system, the Ragtime component loads the migrations
from the supplied resource path, and connects to the dependent
database under the :db
key.
(alter-var-root #'system component/start)
We can then migrate and rollback the started Ragtime component. The
migrate
function will update the database to the latest migration:
(migrate (:ragtime system))
The rollback
function can rollback the database a fixed number of
migrations, or to a specific migration:
(rollback (:ragtime system))
(rollback (:ragtime system) 2)
(rollback (:ragtime system) "005-create-foo")
Copyright © 2016 James Reeves
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close