Skip to content

Instantly share code, notes, and snippets.

@prasann
Last active January 31, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasann/11e62167434eb76a675b54a5b5b672e4 to your computer and use it in GitHub Desktop.
Save prasann/11e62167434eb76a675b54a5b5b672e4 to your computer and use it in GitHub Desktop.
Clojure utility to run database migration with flyway
(ns app.migration
(:require [environ.core :refer [env]])
(:import org.flywaydb.core.Flyway
org.flywaydb.core.internal.info.MigrationInfoDumper))
;; Build DB String from the Environment Variables
(def db-url (str "jdbc:postgresql://"
(env :pg-db-host) ":"
(env :pg-db-port) "/" (env :pg-db-name)))
;; Initialize Flyway object
(def flyway
(let [locations (into-array String ["classpath:db/migration"])]
(doto (new Flyway)
(.setDataSource db-url (env :pg-db-user) (env :pg-db-password) (into-array String []))
(.setLocations locations))))
(defn migrate [] (.migrate flyway))
(defn clean [] (.clean flyway))
(defn reset [] (clean) (migrate))
(defn info []
(println (MigrationInfoDumper/dumpToAsciiTable (.all (.info flyway)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment