Skip to content

Instantly share code, notes, and snippets.

@vitaliel
Last active September 3, 2015 22:35
Show Gist options
  • Save vitaliel/221868 to your computer and use it in GitHub Desktop.
Save vitaliel/221868 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Script to help with rails migrations
cmd = "rake db:migrate"
rev = ARGV[0].to_i
if rev > 0
cmd << " VERSION=#{rev}"
elsif rev == -1
versions = []
Dir["db/migrate/*.rb"].each do |f|
if File.basename(f) =~ /^(\d+)/
versions << $1.to_i
end
end
rev = versions.sort.reverse
rev.shift
cmd << " VERSION=#{rev.first}"
end
puts cmd
system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment