aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration.rb
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-01-10 22:49:44 +0900
committerkennyj <kennyj@gmail.com>2012-01-11 00:35:06 +0900
commitc5ba4896ab4b5d5c8c3d5f3eaf970b600c7a2017 (patch)
tree0bf5373e5db0ec3c38a4f2e6a5c653c1612c2b50 /activerecord/lib/active_record/migration.rb
parent3f38d8442e2c365c6625c647d77f7b31f4da0cd1 (diff)
downloadrails-c5ba4896ab4b5d5c8c3d5f3eaf970b600c7a2017.tar.gz
rails-c5ba4896ab4b5d5c8c3d5f3eaf970b600c7a2017.tar.bz2
rails-c5ba4896ab4b5d5c8c3d5f3eaf970b600c7a2017.zip
migrate(:down) method with table_name_prefix
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r--activerecord/lib/active_record/migration.rb28
1 files changed, 22 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 3d3918c043..c57a637a34 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -344,12 +344,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)
@@ -383,9 +395,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 }
@@ -440,9 +454,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)