Skip to content

Commit

Permalink
Add rollback-until-just-after function for #200 (#201)
Browse files Browse the repository at this point in the history
Co-authored-by: Vincent Pizzo <[email protected]>
  • Loading branch information
vincentjames501 and Vincent Pizzo authored Feb 17, 2021
1 parent 5dee18c commit 596b5e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/migratus/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,16 @@
sort
(take-while #(< % migration-id))
(apply up config))))

(defn rollback-until-just-after
"Migrate down all migrations after migration-id. This only considers completed
migrations, and will not migrate up."
[config migration-id]
(with-store [store (proto/make-store config)]
(->> (completed-migrations config store)
(map proto/id)
distinct
sort
reverse
(take-while #(> % migration-id))
(apply down config))))
12 changes: 12 additions & 0 deletions test/migratus/test/database.clj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@
(is (test-sql/verify-table-exists? config "quux"))
(is (test-sql/verify-table-exists? config "quux2")))

(deftest test-rollback-until-just-after
(core/migrate config)
(is (test-sql/verify-table-exists? config "foo"))
(is (test-sql/verify-table-exists? config "bar"))
(is (test-sql/verify-table-exists? config "quux"))
(is (test-sql/verify-table-exists? config "quux2"))
(core/rollback-until-just-after config 20111202110600)
(is (test-sql/verify-table-exists? config "foo"))
(is (not (test-sql/verify-table-exists? config "bar")))
(is (not (test-sql/verify-table-exists? config "quux")))
(is (not (test-sql/verify-table-exists? config "quux2"))))

(deftest test-migration-ignored-when-already-reserved
(test-with-store
(proto/make-store config)
Expand Down

0 comments on commit 596b5e4

Please sign in to comment.