-
Notifications
You must be signed in to change notification settings - Fork 2
/
migrations.clj
64 lines (52 loc) · 1.73 KB
/
migrations.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(ns parenthesin.helpers.migrations
(:require [migratus.core :as migratus]
[next.jdbc :as jdbc]
[parenthesin.components.config.aero :as config.aero])
(:gen-class))
(defn get-connection []
(let [{:keys [username] :as db} (-> (config.aero/read-config {}) :database)]
(jdbc/get-connection (assoc db :user username))))
(def configuration
{:store :database
:migration-dir "migrations/"})
(defn configuration-with-db []
(assoc configuration :db {:connection (get-connection)}))
(defn init
[config]
(migratus/init config))
(defn migrate
[config]
(migratus/migrate config))
(defn up
[config & args]
(migratus/up config args))
(defn down
[config & args]
(migratus/down config args))
(defn create
[config migration-name]
(migratus/create config migration-name))
(defn rollback
[config]
(migratus/rollback config))
(defn pending-list
[config]
(migratus/pending-list config))
(defn migrate-until-just-before
[config & args]
(migratus/migrate-until-just-before config args))
(defn -main
[& args]
(let [arg (first args)]
(cond
(= arg "init") (init (configuration-with-db))
(= arg "migrate") (migrate (configuration-with-db))
(= arg "up") (up (configuration-with-db) (rest args))
(= arg "down") (down (configuration-with-db) (rest args))
(= arg "create") (create configuration (second args))
(= arg "rollback") (rollback (configuration-with-db))
(= arg "pending-list") (pending-list (configuration-with-db))
(= arg "until-just-before") (migrate-until-just-before (configuration-with-db)
(rest args))
:else
(throw (Exception. (str "Command not found " arg))))))