diff --git a/resources/migrations/018_add_data_migrations_table.yaml b/resources/migrations/018_add_data_migrations_table.yaml index 641e213296dee29202ff5f1e3831136b19589293..7ef821fe35ff6b76d3e2fcffe953a9b51c93ac40 100644 --- a/resources/migrations/018_add_data_migrations_table.yaml +++ b/resources/migrations/018_add_data_migrations_table.yaml @@ -8,7 +8,7 @@ databaseChangeLog: columns: - column: name: id - type: varchar + type: VARCHAR constraints: primaryKey: true nullable: false diff --git a/src/metabase/db.clj b/src/metabase/db.clj index 02566adc2d08eeb831954f761052a5fffe1d3d57..b52a434b56141a9a7736bf0e7bcee80230004118 100644 --- a/src/metabase/db.clj +++ b/src/metabase/db.clj @@ -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)) diff --git a/src/metabase/db/migrations.clj b/src/metabase/db/migrations.clj index bc333ee5c0e10b62f2b55f0f334d82f2d916c794..69c56505168e5b4fd144da81560cc3a1b3ecaced 100644 --- a/src/metabase/db/migrations.clj +++ b/src/metabase/db/migrations.clj @@ -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.