Run pending DB migrations at startup

Run pending DB migrations at startup to make deployement
simpler (eliminates need to clone repo and run "lein migratus migrate"
on the server)
This commit is contained in:
Teemu Patja 2017-01-21 19:11:17 +02:00
parent d39ccd1531
commit 1c26d17ad9
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C

View File

@ -4,7 +4,8 @@
[clojure.java.jdbc :as jdbc]
[conman.core :as conman]
[commiteth.config :refer [env]]
[mount.core :refer [defstate]])
[mount.core :refer [defstate]]
[migratus.core :as migratus])
(:import org.postgresql.util.PGobject
java.sql.Array
clojure.lang.IPersistentMap
@ -15,8 +16,18 @@
Timestamp
PreparedStatement]))
(defn start []
(let [db (env :jdbc-database-url)
migratus-config {:store :database
:migration-dir "migrations/"
:migration-table-name "schema_migrations"
:db db}]
(migratus/migrate migratus-config)
(conman/connect! {:jdbc-url db})))
(defstate ^:dynamic *db*
:start (conman/connect! {:jdbc-url (env :jdbc-database-url)})
:start (start)
:stop (conman/disconnect! *db*))
(conman/bind-connection *db* "sql/queries.sql")