Created
November 19, 2014 09:31
-
-
Save Kungi/f3cb1201aaf532f04b21 to your computer and use it in GitHub Desktop.
namespaces?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def ^:dynamic *db* nil) | |
(defn run-migrations [db files direction] | |
(doseq [file files] | |
(binding [*ns* (find-ns 'clj-sql-up.migrate) | |
*db* db] | |
(files/load-migration-file file) | |
(println "Up found at: " (resolve direction))) | |
(println "Up found at: " (resolve direction)) | |
(println "run migrations found at: " (resolve 'run-migrations)) | |
(let [sql-arr ((resolve direction)) | |
migr-id (files/migration-id file)] | |
(sql/db-transaction* db (fn [trans_db] | |
(if (= direction 'down) | |
(do (println (str "Reversing: " file)) | |
(sql/delete! trans_db :clj_sql_migrations ["name=?" migr-id])) | |
(do (println (str "Migrating: " file)) | |
(sql/insert! trans_db :clj_sql_migrations {:name migr-id}))) | |
(doseq [s sql-arr] | |
(sql/db-do-commands trans_db s))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment