Lein-LB / src / leiningen / lb.clj

Diff from to

File src/leiningen/lb.clj

 rollback   - Rolls back database
 tag        - Tags the database
 dbdoc      - Generates documentation for database/changelogs
+diff       - Reports differences between two database instances
 For help on individual command, append with `--help`, e.g.:
 lein lb update --help
                                          (into acc
                                            {(get rev-opts (as-string opt)) nil}))
                                        (if (contains? acc :more)
-                                         (into acc :more (cons arg (:more acc)))
                                          {:more [arg]})))
                      (if (some #(= arg %) ["--help" "-h" "/?"])
                        (do (print-usage cmd-prefix spec)
                          {:help nil})
-                       (throw (IllegalArgumentException.
-                                (str "Illegal option: " arg))))))]
+                       (into acc :more (cons arg (:more acc))))
+                     (throw (IllegalArgumentException.
+                              (str "Illegal option: " arg)))))]
     (let [opt-map   (reduce get-opts {} args)
           with-arg? (fn []
                       (every? (fn [row]
             (lb/generate-doc changelog out-dir (ctx-list contexts))))))))
+(defn parse-diff-args
+  "Parse arguments for `diff` command."
+  [& args]
+  (parse-opts "lein lb diff"
+    args
+    ["Clj-DBCP profile name (default if unspecified)" :opt-arg  :profile     :p]
+    ["Reference Clj-DBCP profile name"                :with-arg :ref-profile :r]))
+(defn diff
+  "Report differences between two database instances"
+  [& args]
+  (let [opt (apply parse-diff-args args)]
+    (when-not (contains? opt :help)
+      (let [profile     (:profile     opt)
+            ref-profile (:ref-profile opt)]
+        ;; begin with reference DB profile
+        (sp/with-dbspec
+          (cp/db-spec (make-datasource ref-profile))
+          (sp/with-connection
+            sp/*dbspec*
+            (let [ref-db (lb/make-db-instance (:connection sp/*dbspec*))]
+              ;; go on to target DB profile
+              (sp/with-dbspec (cp/db-spec (make-datasource profile))
+                              (lb/with-lb
+                                (lb/diff ref-db))))))))))
 ;; ----- Leiningen plugin command -----
 (defn lb
+  "Entry point for the Lein-LB plugin."
   [project & args]
   (let [argc (count args)
         cmd  (or (first args) "")]
       "version"    (println (format "Lein-LB version %s"
                               (apply str (interpose "." version))))
       "dbcp-props" (println (slurp (io/resource "")))
-      "update"     (eip-fn project update (rest args)
-                     [:changelog :profile :chs-count :contexts :sql-only])
+      "update"     (eip-fn project update   (rest args)
+                           [:changelog :profile :chs-count :contexts :sql-only])
       "rollback"   (eip-fn project rollback (rest args)
-                     [:changelog :profile :chs-count :tag :date :contexts :sql-only])
-      "tag"        (eip-fn project tag (rest args)
-                     [:profile :tag])
-      "dbdoc"      (eip-fn project dbdoc (rest args)
-                     [:changelog :profile :output-dir :contexts])
+                           [:changelog :profile :chs-count :tag :date :contexts :sql-only])
+      "tag"        (eip-fn project tag      (rest args)
+                           [:profile :tag])
+      "dbdoc"      (eip-fn project dbdoc    (rest args)
+                           [:changelog :profile :output-dir :contexts])
+      "diff"       (eip-fn project diff     (rest args)
+                           [:profile :ref-profile])
         (println (format "Invalid command: %s" cmd))
         (lb project "help")))))