Created
June 18, 2013 22:38
-
-
Save ajsharp/5810125 to your computer and use it in GitHub Desktop.
rake db:migrate:rerun VERSION=123
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
namespace :db do | |
namespace :migrate do | |
desc "Re-run a migration that's already been run" | |
task :rerun => [:environment, :load_config] do | |
class ActiveRecord::Migrator | |
def rerun | |
target = migrations.detect { |m| m.version == @target_version } | |
raise UnknownMigrationVersionError.new(@target_version) if target.nil? | |
target.migrate(:up) | |
end | |
def self.rerun(*args) | |
new(*args).rerun | |
end | |
end | |
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil | |
raise 'VERSION is required' unless version | |
ActiveRecord::Migrator.rerun(:rerun, ActiveRecord::Migrator.migrations_paths, version) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment