Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created June 18, 2013 22:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajsharp/5810125 to your computer and use it in GitHub Desktop.
Save ajsharp/5810125 to your computer and use it in GitHub Desktop.
rake db:migrate:rerun VERSION=123
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