-
Notifications
You must be signed in to change notification settings - Fork 11
/
seed.clj
36 lines (33 loc) · 1.43 KB
/
seed.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
(ns framework.db.seed
(:require
[framework.config.core :as config]
[migratus.core :as migratus]
[next.jdbc :as jdbc]
[xiana.commons :refer [rename-key]]))
(defn seed!
([config]
(let [db-conf (if-let [datasource (some-> (get-in config [:xiana/postgresql :datasource])
jdbc/get-datasource)]
{:datasource datasource}
(:xiana/postgresql config))
mig-config (-> (assoc (:xiana/migration config) :db db-conf)
(rename-key :seeds-dir :migration-dir)
(rename-key :seeds-table-name :migration-table-name))]
(migratus/migrate mig-config))
config))
(def seed-config
(let [config (config/config)
db-conf (:xiana/postgresql config)]
(-> (assoc (:xiana/migration config) :db db-conf)
(rename-key :seeds-dir :migration-dir)
(rename-key :seeds-table-name :migration-table-name))))
(defn -main [& args]
(let [[command name type] args]
(if (and (:migration-dir seed-config) (:migration-table-name seed-config))
(case command
"create" (migratus/create seed-config name (keyword type))
"reset" (migratus/reset seed-config)
"destroy" (migratus/destroy seed-config)
"migrate" (migratus/migrate seed-config)
(println "You can 'create' 'reset' 'destroy' or 'migrate' your seed data"))
(println "No seed configuration found"))))