aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-19 10:31:03 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-19 10:31:03 -0800
commit47017bd1697d6b4d6780356a403f91536eacd689 (patch)
tree72619dbd4cf2c997d72a70cecd14babfacc369df
parent6519df4157a861c9c9d567ee57983ded0e967a10 (diff)
downloadrails-47017bd1697d6b4d6780356a403f91536eacd689.tar.gz
rails-47017bd1697d6b4d6780356a403f91536eacd689.tar.bz2
rails-47017bd1697d6b4d6780356a403f91536eacd689.zip
invertable migrations are working
-rw-r--r--activerecord/lib/active_record/migration.rb20
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb2
-rw-r--r--activerecord/test/cases/invertable_migration_test.rb5
3 files changed, 20 insertions, 7 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 = []
diff --git a/activerecord/test/cases/invertable_migration_test.rb b/activerecord/test/cases/invertable_migration_test.rb
index 2477048954..ab08cf6fe2 100644
--- a/activerecord/test/cases/invertable_migration_test.rb
+++ b/activerecord/test/cases/invertable_migration_test.rb
@@ -21,11 +21,6 @@ module ActiveRecord
end
end
- def test_invertable?
- migration = InvertableMigration.new
- assert migration.invertable?, 'should be invertable'
- end
-
def test_up
migration = InvertableMigration.new
migration.migrate(:up)