yogthos / migratus

MIGRATE ALL THE THINGS!
642 stars 93 forks source link

Add a function to rollback to a target migration similar to migrate-until-just-before for ups #200

Open vincentjames501 opened 3 years ago

vincentjames501 commented 3 years ago

Right now you can only down migrations by a specific id(s). Sometimes, I want to rollback to a specific point similar to going up to a specific point via migratus.core/migrate-until-just-before. Could the implementation be as simple as:

(defn rollback-until-just-after
  [config migration-id]
  (with-store [store (proto/make-store config)]
              (->> (uncompleted-migrations config store)
                   (map proto/id)
                   distinct
                   sort
                   reverse
                   (take-while #(> % migration-id))
                   (apply down config))))

Does this make sense?

yogthos commented 3 years ago

Yeah, I think that would be reasonable. If you want to make a PR with the feature and maybe add a test, I'll push out a release.

vincentjames501 commented 3 years ago

PR sent w/ test added.

yogthos commented 3 years ago

Fantastic, just pushed 1.3.5 to Clojars with the new functionality. :tada: