method
migrate
v3.2.13 -
Show latest stable
- Class:
ActiveRecord::Migration
migrate(direction)public
Execute this migration in the named direction
# File activerecord/lib/active_record/migration.rb, line 380
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 {
self.revert {
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 Related methods
- Instance methods
- announce
- connection
- copy
- down
- method_missing
- migrate
- next_migration_number
- revert
- reverting?
- say
- say_with_time
- suppress_messages
- up
- write
- Class methods
- method_missing
- migrate
- new