Skip to content

Instantly share code, notes, and snippets.

@ivanyv
Created June 13, 2011 16:39
Show Gist options
  • Save ivanyv/1023139 to your computer and use it in GitHub Desktop.
Save ivanyv/1023139 to your computer and use it in GitHub Desktop.
Painfully specify Rails migration versions for rake db:migrate
# 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
@ivanyv
Copy link
Author

ivanyv commented Jun 13, 2011

Quick and dirty solution. Any suggestions?

@ivanyv
Copy link
Author

ivanyv commented Jun 13, 2011

I just realized you need to add gem 'highline' in your Gemfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment