-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.clj
54 lines (42 loc) · 1.42 KB
/
user.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
(ns user
(:require [g2.config :refer [env]]
[clojure.spec.alpha :as s]
[expound.alpha :as expound]
[mount.core :as mount]
[g2.core :refer [start-app]]
[g2.db.core]
[clojure.tools.logging :as log]
[conman.core :as conman]
[luminus-migrations.core :as migrations]))
(alter-var-root #'s/*explain-out* (constantly expound/printer))
(add-tap (bound-fn* clojure.pprint/pprint))
(defn start
"Starts application.
You'll usually want to run this on startup."
[]
(mount/start-without #'g2.core/repl-server))
(defn stop
"Stops application."
[]
(mount/stop-except #'g2.core/repl-server))
(defn restart
"Restarts application."
[]
(stop)
(start))
(defn restart-db []
(mount/stop #'g2.db.core/*db*)
(mount/start #'g2.db.core/*db*)
(binding [*ns* 'g2.db.core]
(conman/bind-connection g2.db.core/*db* "sql/queries.sql")))
(defn reset-db []
(migrations/migrate ["reset"] (select-keys env [:database-url])))
(defn migrate []
"apply pending migrations"
(migrations/migrate ["migrate"] (select-keys env [:database-url])))
(defn rollback []
"rollback the last migration applied"
(migrations/migrate ["rollback"] (select-keys env [:database-url])))
(defn create-migration [name]
"Rollback all migrations that have been run, and then apply all migrations."
(migrations/create name (select-keys env [:database-url])))