Railsは接続プールを使用するため、ActiveRecord ::ConnectionAdapters ::ConnectionPool#new_connection
にalias_method_chainを使用するのが最善の策です。module ActiveRecord
Module ConnectionAdapters
class ConnectionPool
alias_method_chain :new_connection, :my_stuff
private
def new_connection_with_my_stuff
c = new_connection_without_my_stuff
# Do your stuff with
# c.exec(<your sql command>)
c
end
end
end
end