diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-23 10:50:16 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-23 10:50:16 -0700 |
commit | 0382e440800740c53f43e4fcb378b38d0150b853 (patch) | |
tree | 2684d2db24d0d548d20252ddc1a49d9b72b1344f /activerecord/lib | |
parent | ef48cea16920a50b772eebdde1c364144380df05 (diff) | |
parent | 565bfb9cd49285ebaa170141b4996c22ba81de43 (diff) | |
download | rails-0382e440800740c53f43e4fcb378b38d0150b853.tar.gz rails-0382e440800740c53f43e4fcb378b38d0150b853.tar.bz2 rails-0382e440800740c53f43e4fcb378b38d0150b853.zip |
Merge pull request #5537 from kennyj/fix_4399-32
[3-2-stable] migrate(:down) method with table_name_prefix
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index fb25754f56..e6686597b7 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -346,12 +346,24 @@ module ActiveRecord @name = self.class.name @version = nil @connection = nil + @reverting = false end # instantiate the delegate object after initialize is defined self.verbose = true self.delegate = new + def revert + @reverting = true + yield + ensure + @reverting = false + end + + def reverting? + @reverting + end + def up self.class.delegate = self return unless self.class.respond_to?(:up) @@ -385,9 +397,11 @@ module ActiveRecord end @connection = conn time = Benchmark.measure { - recorder.inverse.each do |cmd, args| - send(cmd, *args) - end + self.revert { + recorder.inverse.each do |cmd, args| + send(cmd, *args) + end + } } else time = Benchmark.measure { change } @@ -442,9 +456,11 @@ module ActiveRecord arg_list = arguments.map{ |a| a.inspect } * ', ' say_with_time "#{method}(#{arg_list})" do - unless arguments.empty? || method == :execute - arguments[0] = Migrator.proper_table_name(arguments.first) - arguments[1] = Migrator.proper_table_name(arguments.second) if method == :rename_table + unless reverting? + unless arguments.empty? || method == :execute + arguments[0] = Migrator.proper_table_name(arguments.first) + arguments[1] = Migrator.proper_table_name(arguments.second) if method == :rename_table + end end return super unless connection.respond_to?(method) connection.send(method, *arguments, &block) |