Skip to content

Commit 0633509

Browse files
author
Albert Lai
committed
Clean up code
1 parent 9596e31 commit 0633509

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

deps.edn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"-O" "-enable-all-security-services"
1414
"-O" "-initialize-at-run-time=org.postgresql.sspi.SSPIClient"]}}
1515
:deps {org.clojure/clojure {:mvn/version "1.9.0"}
16-
duct/migrator.ragtime {:git/url "https://github.com/zerg000000/migrator.ragtime.git" :sha "dba95e5b5645e4cd1e81b1d0a316cfccdc899016"}
16+
duct/migrator.ragtime {:git/url "https://github.com/zerg000000/migrator.ragtime.git" :sha "1562879f4e3173d755717b6fed9aad21e9dc7513"}
1717
duct/core {:mvn/version "0.8.0"}
1818
org.postgresql/postgresql {:mvn/version "42.2.8"}
1919
ragtime/jdbc {:git/url "https://github.com/zerg000000/ragtime.git" :deps/root "jdbc" :sha "81033b3520c026ea0504e8adb6dbed1640a060f6"}
2020
cli-matic {:mvn/version "0.3.9"
21-
:exclusions [org.clojure/spec.alpha]}}}
21+
:exclusions [org.clojure/spec.alpha]}}}

src/ragtime/cli/core.clj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[ragtime.reporter :as reporter]
55
[ragtime.jdbc :as jdbc]
66
[ragtime.protocols :as p]
7-
[duct.core.resource]
87
[duct.migrator.ragtime :as migrator]
98
[clojure.pprint :as pp]))
109

@@ -33,8 +32,8 @@
3332
(defmulti info (fn [{:keys [mode]}] mode))
3433

3534
(defmethod info :default
36-
[{:keys [migrations] :as opts}]
37-
(let [applied-migrations (p/applied-migration-ids (get-database opts))
35+
[{:keys [database migrations] :as opts}]
36+
(let [applied-migrations (p/applied-migration-ids database)
3837
list (map (fn [idx applied-id mig]
3938
{:idx idx
4039
:migration-id (when mig (p/id mig))
@@ -52,16 +51,16 @@
5251
mode))
5352

5453
(defmethod migrate-all :default
55-
[{:keys [migrations] :as opts}]
56-
(ragtime/migrate-all (get-database opts) {} migrations opts))
54+
[{:keys [database migrations] :as opts}]
55+
(ragtime/migrate-all database (ragtime/into-index migrations) migrations opts))
5756

5857
(defmethod rollback-to :default
59-
[{:keys [migration-id migrations] :as opts}]
60-
(ragtime/rollback-to (get-database opts) (ragtime/into-index migrations) migration-id opts))
58+
[{:keys [database migration-id migrations] :as opts}]
59+
(ragtime/rollback-to database (ragtime/into-index migrations) migration-id opts))
6160

6261
(defmethod rollback-last :default
63-
[{:keys [last-n migrations] :as opts}]
64-
(ragtime/rollback-last (get-database opts) (ragtime/into-index migrations) last-n opts))
62+
[{:keys [last-n migrations database] :as opts}]
63+
(ragtime/rollback-last database (ragtime/into-index migrations) last-n opts))
6564

6665

6766
(extend-protocol migrator/StringSource

src/ragtime/cli/dir.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
(defmethod cc/prepare-options :dir
77
[{:keys [database-url strategy resources-dir reporter] :as ins}]
88
(let [migrations (jdbc/load-directory resources-dir)
9-
opts {:database {:spec {:connection-uri database-url}}
9+
opts {:database (cc/get-database (assoc ins :database {:spec {:connection-uri database-url}}))
1010
:strategy (cc/get-strategy strategy)
1111
:reporter (cc/get-reporter reporter)
1212
:migrations migrations}]
13-
(merge ins opts)))
13+
(merge ins opts)))

src/ragtime/cli/duct.clj

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77

88
(duct/load-hierarchy)
99

10-
(defn- migrate [index {:keys [migrations] :as opts}]
11-
(let [db (cc/get-database opts)
12-
strat (cc/get-strategy opts)
13-
rep (:reporter opts)]
14-
(ragtime/migrate-all db index migrations {:reporter rep, :strategy strat})
15-
(ragtime/into-index index migrations)))
16-
1710
(defn get-config [config-file resources-dir]
1811
(duct/read-config (io/file config-file)
1912
{'duct/resource (fn [f] (io/file (str resources-dir f)))}))
@@ -28,7 +21,7 @@
2821
{} config))
2922

3023
(defmethod cc/prepare-options :duct
31-
[{:keys [database-url config-file resources-dir reporter] :as ins}]
24+
[{:keys [database-url config-file resources-dir reporter strategy] :as ins}]
3225
(let [raw-config (get-config config-file resources-dir)
3326
migration-order (get-in raw-config [:duct.profile/base :duct.migrator/ragtime :migrations])
3427
config (-> raw-config
@@ -37,12 +30,9 @@
3730
(ig/init [:duct.migrator.ragtime/sql]))]
3831
(merge
3932
ins
40-
{:database {:spec {:connection-uri database-url}}
33+
{:database (cc/get-database (assoc ins :database {:spec {:connection-uri database-url}}))
34+
:strategy (cc/get-strategy strategy)
4135
:reporter (cc/get-reporter reporter)
42-
:migrations (map (fn [{:keys [key]}]
43-
(get config [:duct.migrator.ragtime/sql key]))
36+
:migrations (mapv (fn [{:keys [key]}]
37+
(get config [:duct.migrator.ragtime/sql key]))
4438
migration-order)})))
45-
46-
(defmethod cc/migrate-all :duct
47-
[opts]
48-
(migrate {} opts))

0 commit comments

Comments
 (0)