Permalink
Browse files

Check for empty migrations by filetype

  • Loading branch information...
swlkr committed Jan 11, 2019
1 parent a27f0b9 commit 3e88c3c0e351308537a3d03ea422ecc002320c5b
Showing with 21 additions and 3 deletions.
  1. +21 −3 src/coast/migrations.clj
@@ -42,14 +42,23 @@
completed (set (completed-migrations))]
(sort (vec (set/difference all completed)))))


(defn migration-blank? [migration]
(let [ext (last (re-find #"\.(\w+)$" migration))]
(condp = ext
"sql" (string/blank? (migrations.sql/up migration))
"edn" (empty? (migrations.edn/content migration))
true)))


(defn migrate []
(let [migrations (pending)]
(doseq [migration migrations]
(let [sql (or (migrations.sql/up migration)
(migrations.edn/migrate migration))
edn (migrations.edn/content migration)
friendly-name (string/replace migration #"\..*$" "")]
(if (string/blank? sql)
friendly-name (string/replace migration #"\.edn|\.sql" "")]
(if (migration-blank? migration)
(throw (Exception. (format "%s is empty" migration)))
(do
(println "")
@@ -65,14 +74,23 @@
(schema/save edn))
(println friendly-name "migrated successfully")))))))


(defn rollback-blank? [migration]
(let [ext (last (re-find #"\.(\w+)$" migration))]
(condp = ext
"sql" (string/blank? (migrations.sql/down migration))
"edn" (empty? (migrations.edn/rollback migration))
true)))


(defn rollback []
(let [migration (last (completed-migrations))]
(when (some? migration)
(let [sql (or (migrations.sql/down migration)
(migrations.edn/rollback migration))
edn (migrations.edn/content migration)
friendly-name (string/replace migration #"\.edn|\.sql" "")]
(if (string/blank? sql)
(if (rollback-blank? migration)
(throw (Exception. (format "%s is empty" migration)))
(do
(println "")

0 comments on commit 3e88c3c

Please sign in to comment.