Last active
September 3, 2015 22:35
-
-
Save vitaliel/221868 to your computer and use it in GitHub Desktop.
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
#!/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