Skip to content

Commit

Permalink
Update to version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ejschoen committed Nov 27, 2018
1 parent e33c10d commit 12f4429
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject cc.artifice/tern-validate "1.1.1"
(defproject cc.artifice/tern-validate "1.2.0"
:description "Insert tern database schema version into the project manifest."
:url "http://bitbucket.org/i2kconnect/tern-validate"
:license {:name "Eclipse Public License"
Expand Down
22 changes: 19 additions & 3 deletions src/tern_validate/core.clj
Expand Up @@ -30,12 +30,28 @@


(defn get-database-schema-version-in-repl
[]
[& [project]]
(let [files (try (sort (map #(.getName %)
(filter #(.endsWith (.getName %) ".edn") (file-seq (io/file "migrations/")))))
(filter #(.endsWith (.getName %) ".edn")
(file-seq
(if (and project (get-in project [:tern :migration-dir]))
(let [migration-dir (get-in project [:tern :migration-dir])]
(if (.startsWith migration-dir "/")
;; Absolute path --> Assume it's actually a path under resources
(let [resource-paths (:resource-paths project ["resources"])
migration-path (some (fn [rp]
(let [migration-path (str rp migration-dir)]
(and (.exists (io/file migration-path))
migration-path)))
resource-paths)]
(if migration-path
(io/file migration-path)
(io/file "migrations/")))
(io/file migration-dir)))
(io/file "migrations/"))))))
(catch Exception e (println (format "Failed to get migration files: %s" (.getMessage e))) nil))
last-file (last files)
version (when last-file (second (re-matches #"(\d+)-(.*)" last-file)))]
version (when last-file (second (re-matches #"(\d+)-(.*)" last-file)))]
version))

(defn get-database-schema-version-from-project
Expand Down
9 changes: 6 additions & 3 deletions src/tern_validate/plugin.clj
Expand Up @@ -25,16 +25,19 @@

(defn middleware
[project]
(let [version (tv/get-database-schema-version-in-repl)
(let [version (tv/get-database-schema-version-in-repl project)
dependency (get-plugin-version)]
;;(leiningen.core.main/info (format "Tern validate is %s" (pr-str dependency)))
(if (and (not-empty version) (not-empty (get-in project [:manifest "Database-Schema-Version"])))
project
(let [new-project (if version
(do ;;(leiningen.core.main/info (format "Setting schema version to %s" version))
;; The info is commented out here, because it gets executed too many times.
(do #_(leiningen.core.main/info
(format "Libraries that link against %s %s will expect database schema version %s"
(:name project) (:version project) version))
(-> project
(assoc-in [:manifest "Database-Schema-Version"] version) ))
(do ;;(leiningen.core.main/warn (format "Unable to determine database schema version."))
(do (leiningen.core.main/warn (format "Unable to determine database schema version."))
project))]
(if (some #(= dependency %) (get-in new-project [:dependencies]))
new-project
Expand Down

0 comments on commit 12f4429

Please sign in to comment.