Skip to content

Instantly share code, notes, and snippets.

@c0mrade
Forked from n0ts/set_schema_migrations.rb
Last active August 29, 2015 14:15
Show Gist options
  • Save c0mrade/dbd01ab80d41e5794d2e to your computer and use it in GitHub Desktop.
Save c0mrade/dbd01ab80d41e5794d2e to your computer and use it in GitHub Desktop.
require 'optparse'
ENV['RAILS_ENV'] = ENV['RAILS_ENV'] || 'development'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
opts = {}
ARGV.options {|opt|
opt.on('-s', '--save', 'save') {|v| opts[:save] = v }
opt.parse!
}
Dir::entries("#{RAILS_ROOT}/db/migrate/").sort.each do |v|
next if v == "." or v == ".." or v == ".svn"
version, name = v.split('_', 2)
begin
if opts[:save]
ActiveRecord::Base.connection.execute("INSERT INTO schema_migrations values ('#{version}')")
end
rescue => e
p e
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment