Created
March 17, 2011 08:16
-
-
Save n0ts/873997 to your computer and use it in GitHub Desktop.
insert db migration version to schema_migrations table
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
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 | |
ActiveRecord::SchemaMigration.create(version)
To specify @jurielsz7 answer, then the argument must be passed as a hash, otherwise ArgumentError (When assigning attributes, you must pass a hash as an argument, String passed.)
error will be given.
So in following form it works as expected: ActiveRecord::SchemaMigration.create(version: '20211023125427')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍