Skip to content

Commit

Permalink
Use ActiveRecord::Migration#connection instead of @connection
Browse files Browse the repository at this point in the history
`ActiveRecord::Migration` has `connetion` method so replace to use
`connection` method to get `@connection` as much as possible
  • Loading branch information
yui-knk committed Aug 23, 2015
1 parent 55320fa commit 1591c34
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -475,13 +475,13 @@ def initialize(name = self.class.name, version = nil)
def revert(*migration_classes)
run(*migration_classes.reverse, revert: true) unless migration_classes.empty?
if block_given?
if @connection.respond_to? :revert
@connection.revert { yield }
if connection.respond_to? :revert
connection.revert { yield }
else
recorder = CommandRecorder.new(@connection)
recorder = CommandRecorder.new(connection)
@connection = recorder
suppress_messages do
@connection.revert { yield }
connection.revert { yield }
end
@connection = recorder.delegate
recorder.commands.each do |cmd, args, block|
Expand All @@ -492,7 +492,7 @@ def revert(*migration_classes)
end

def reverting?
@connection.respond_to?(:reverting) && @connection.reverting
connection.respond_to?(:reverting) && connection.reverting
end

class ReversibleBlockHelper < Struct.new(:reverting) # :nodoc:
Expand Down Expand Up @@ -549,7 +549,7 @@ def run(*migration_classes)
revert { run(*migration_classes, direction: dir, revert: true) }
else
migration_classes.each do |migration_class|
migration_class.new.exec_migration(@connection, dir)
migration_class.new.exec_migration(connection, dir)
end
end
end
Expand Down Expand Up @@ -641,7 +641,7 @@ def method_missing(method, *arguments, &block)
arg_list = arguments.map(&:inspect) * ', '

say_with_time "#{method}(#{arg_list})" do
unless @connection.respond_to? :revert
unless connection.respond_to? :revert
unless arguments.empty? || [:execute, :enable_extension, :disable_extension].include?(method)
arguments[0] = proper_table_name(arguments.first, table_name_options)
if [:rename_table, :add_foreign_key].include?(method) ||
Expand Down

0 comments on commit 1591c34

Please sign in to comment.