Created
June 13, 2011 16:39
-
-
Save ivanyv/1023139 to your computer and use it in GitHub Desktop.
Painfully specify Rails migration versions for rake db:migrate
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
# Put this inside Rakefile | |
if ENV['VERSION'].present? && ENV['VERSION'].to_i.to_s != ENV['VERSION'] | |
pattern = '*' + ENV['VERSION'].split(//).map { |l| "#{l}*" }.join | |
migrations = Dir[File.join(Rails.root, 'db', 'migrate', pattern)] | |
if migrations.size == 0 | |
puts "No migrations matching `#{ENV['VERSION']}` found." | |
exit | |
else | |
migration = File.basename(migrations.first) | |
if migrations.size > 1 | |
require 'highline' | |
puts "Select a migration:" | |
migration = HighLine.new.choose(*(migrations.map { |m| File.basename(m) } + [ 'Cancel' ])) | |
exit if migration == 'Cancel' | |
end | |
puts "Running #{migration}..." | |
ENV['VERSION'] = migration.to_i.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just realized you need to add
gem 'highline'
in your Gemfile.