instance method
migrate
Ruby on Rails 3.1.12
Since v3.1.12Signature
migrate(direction)
Execute this migration in the named direction
Parameters
-
directionreq
Source
# File activerecord/lib/active_record/migration.rb, line 366
def migrate(direction)
return unless respond_to?(direction)
case direction
when :up then announce "migrating"
when :down then announce "reverting"
end
time = nil
ActiveRecord::Base.connection_pool.with_connection do |conn|
@connection = conn
if respond_to?(:change)
if direction == :down
recorder = CommandRecorder.new(@connection)
suppress_messages do
@connection = recorder
change
end
@connection = conn
time = Benchmark.measure {
recorder.inverse.each do |cmd, args|
send(cmd, *args)
end
}
else
time = Benchmark.measure { change }
end
else
time = Benchmark.measure { send(direction) }
end
@connection = nil
end
case direction
when :up then announce "migrated (%.4fs)" % time.real; write
when :down then announce "reverted (%.4fs)" % time.real; write
end
end
Defined in activerecord/lib/active_record/migration.rb line 366
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Migration