Skip to content
Snippets Groups Projects
Commit bf0648d0 authored by Cam Saül's avatar Cam Saül
Browse files

`defmigration` macro for defining data migrations

parent 90acc943
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ databaseChangeLog:
columns:
- column:
name: id
type: varchar
type: VARCHAR
constraints:
primaryKey: true
nullable: false
......
......@@ -95,6 +95,7 @@
* `:up` - Migrate up
* `:down` - Rollback *all* migrations
* `:down-one` - Rollback a single migration
* `:print` - Just print the SQL for running the migrations, don't actually run them.
* `:release-locks` - Manually release migration locks left by an earlier failed migration.
(This shouldn't be necessary now that we run migrations inside a transaction,
......@@ -110,6 +111,7 @@
(case direction
:up (.update liquibase "")
:down (.rollback liquibase 10000 "")
:down-one (.rollback liquibase 1 "")
:print (let [writer (StringWriter.)]
(.update liquibase "" writer)
(.toString writer))
......
......@@ -12,9 +12,10 @@
;;; # Migration Helpers
(defn- migration-ran? [migration]
(boolean (seq (k/select "data_migrations"
(k/where {:id (name migration)})
(k/limit 1)))))
(-> (k/select :data_migrations
(k/aggregate (count :*) :count)
(k/where {:id (name migration)}))
first :count (> 0)))
(defn- run-migration-if-needed
"Run MIGRATION if needed. MIGRATION should be a symbol naming a fn that takes no arguments.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment