aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/migration.rb20
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb2
2 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index e7063bca11..99dd50ccb1 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -332,7 +332,25 @@ module ActiveRecord
time = nil
ActiveRecord::Base.connection_pool.with_connection do |conn|
@connection = conn
- time = Benchmark.measure { send(direction) }
+ 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
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index fa189b8009..fc669d2e89 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -3,7 +3,7 @@ module ActiveRecord
# ActiveRecord::Migration::CommandRecorder records commands done during
# a migration and knows how to reverse those commands.
class CommandRecorder
- attr_reader :commands, :delegate
+ attr_accessor :commands, :delegate
def initialize(delegate = nil)
@commands = []