Created
November 16, 2020 08:16
-
-
Save Dounx/e6ee5abfcc91d2577914f0e3797ce790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rollback(migrations_path) | |
migrations_paths_was = ActiveRecord::Migrator.migrations_paths | |
ActiveRecord::Migrator.migrations_paths = [migrations_path] | |
ActiveRecord::Tasks::DatabaseTasks.check_target_version | |
scope = ENV["SCOPE"] | |
verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, ActiveRecord::Tasks::DatabaseTasks.send(:verbose?) | |
ActiveRecord::Base.connection.migration_context.down(ActiveRecord::Tasks::DatabaseTasks.target_version) do |migration| | |
scope.blank? || scope == migration.scope | |
end | |
ActiveRecord::Base.clear_cache! | |
ensure | |
ActiveRecord::Migrator.migrations_paths = migrations_paths_was - [migrations_path] | |
ActiveRecord::Migration.verbose = verbose_was | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment