mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42442 from Shopify/active-record-cattr-legacy-connection
Make `legacy_connection_handling` a module instance variable
This commit is contained in:
commit
9e66e5d027
20 changed files with 82 additions and 70 deletions
|
@ -169,6 +169,9 @@ module ActiveRecord
|
||||||
autoload :TestDatabases, "active_record/test_databases"
|
autoload :TestDatabases, "active_record/test_databases"
|
||||||
autoload :TestFixtures, "active_record/fixtures"
|
autoload :TestFixtures, "active_record/fixtures"
|
||||||
|
|
||||||
|
singleton_class.attr_accessor :legacy_connection_handling
|
||||||
|
self.legacy_connection_handling = true
|
||||||
|
|
||||||
def self.eager_load!
|
def self.eager_load!
|
||||||
super
|
super
|
||||||
ActiveRecord::Locking.eager_load!
|
ActiveRecord::Locking.eager_load!
|
||||||
|
|
|
@ -100,7 +100,7 @@ module ActiveRecord
|
||||||
# See +READ_QUERY+ for the queries that are blocked by this
|
# See +READ_QUERY+ for the queries that are blocked by this
|
||||||
# method.
|
# method.
|
||||||
def while_preventing_writes(enabled = true)
|
def while_preventing_writes(enabled = true)
|
||||||
unless ActiveRecord::Base.legacy_connection_handling
|
unless ActiveRecord.legacy_connection_handling
|
||||||
raise NotImplementedError, "`while_preventing_writes` is only available on the connection_handler with legacy_connection_handling"
|
raise NotImplementedError, "`while_preventing_writes` is only available on the connection_handler with legacy_connection_handling"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ module ActiveRecord
|
||||||
payload[:config] = db_config.configuration_hash
|
payload[:config] = db_config.configuration_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
owner_to_pool_manager[pool_config.connection_specification_name] ||= LegacyPoolManager.new
|
owner_to_pool_manager[pool_config.connection_specification_name] ||= LegacyPoolManager.new
|
||||||
else
|
else
|
||||||
owner_to_pool_manager[pool_config.connection_specification_name] ||= PoolManager.new
|
owner_to_pool_manager[pool_config.connection_specification_name] ||= PoolManager.new
|
||||||
|
|
|
@ -140,7 +140,7 @@ module ActiveRecord
|
||||||
# will return true based on +current_preventing_writes+.
|
# will return true based on +current_preventing_writes+.
|
||||||
def preventing_writes?
|
def preventing_writes?
|
||||||
return true if replica?
|
return true if replica?
|
||||||
return ActiveRecord::Base.connection_handler.prevent_writes if ActiveRecord::Base.legacy_connection_handling
|
return ActiveRecord::Base.connection_handler.prevent_writes if ActiveRecord.legacy_connection_handling
|
||||||
return false if connection_klass.nil?
|
return false if connection_klass.nil?
|
||||||
|
|
||||||
connection_klass.current_preventing_writes
|
connection_klass.current_preventing_writes
|
||||||
|
|
|
@ -135,7 +135,7 @@ module ActiveRecord
|
||||||
# Dog.first # finds first Dog record stored on the shard one replica
|
# Dog.first # finds first Dog record stored on the shard one replica
|
||||||
# end
|
# end
|
||||||
def connected_to(role: nil, shard: nil, prevent_writes: false, &blk)
|
def connected_to(role: nil, shard: nil, prevent_writes: false, &blk)
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
if self != Base
|
if self != Base
|
||||||
raise NotImplementedError, "`connected_to` can only be called on ActiveRecord::Base with legacy connection handling."
|
raise NotImplementedError, "`connected_to` can only be called on ActiveRecord::Base with legacy connection handling."
|
||||||
end
|
end
|
||||||
|
@ -176,7 +176,7 @@ module ActiveRecord
|
||||||
def connected_to_many(*classes, role:, shard: nil, prevent_writes: false)
|
def connected_to_many(*classes, role:, shard: nil, prevent_writes: false)
|
||||||
classes = classes.flatten
|
classes = classes.flatten
|
||||||
|
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
raise NotImplementedError, "connected_to_many is not available with legacy connection handling"
|
raise NotImplementedError, "connected_to_many is not available with legacy connection handling"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ module ActiveRecord
|
||||||
# It is not recommended to use this method in a request since it
|
# It is not recommended to use this method in a request since it
|
||||||
# does not yield to a block like +connected_to+.
|
# does not yield to a block like +connected_to+.
|
||||||
def connecting_to(role: default_role, shard: default_shard, prevent_writes: false)
|
def connecting_to(role: default_role, shard: default_shard, prevent_writes: false)
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
raise NotImplementedError, "`connecting_to` is not available with `legacy_connection_handling`."
|
raise NotImplementedError, "`connecting_to` is not available with `legacy_connection_handling`."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ module ActiveRecord
|
||||||
# See +READ_QUERY+ for the queries that are blocked by this
|
# See +READ_QUERY+ for the queries that are blocked by this
|
||||||
# method.
|
# method.
|
||||||
def while_preventing_writes(enabled = true, &block)
|
def while_preventing_writes(enabled = true, &block)
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
connection_handler.while_preventing_writes(enabled, &block)
|
connection_handler.while_preventing_writes(enabled, &block)
|
||||||
else
|
else
|
||||||
connected_to(role: current_role, prevent_writes: enabled, &block)
|
connected_to(role: current_role, prevent_writes: enabled, &block)
|
||||||
|
@ -239,7 +239,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_connection_handler(handler_key) # :nodoc:
|
def lookup_connection_handler(handler_key) # :nodoc:
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
handler_key ||= ActiveRecord::Base.writing_role
|
handler_key ||= ActiveRecord::Base.writing_role
|
||||||
connection_handlers[handler_key] ||= ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
connection_handlers[handler_key] ||= ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
||||||
else
|
else
|
||||||
|
@ -249,7 +249,7 @@ module ActiveRecord
|
||||||
|
|
||||||
# Clears the query cache for all connections associated with the current thread.
|
# Clears the query cache for all connections associated with the current thread.
|
||||||
def clear_query_caches_for_current_thread
|
def clear_query_caches_for_current_thread
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.connection_handlers.each_value do |handler|
|
ActiveRecord::Base.connection_handlers.each_value do |handler|
|
||||||
clear_on_handler(handler)
|
clear_on_handler(handler)
|
||||||
end
|
end
|
||||||
|
@ -358,7 +358,7 @@ module ActiveRecord
|
||||||
def with_role_and_shard(role, shard, prevent_writes)
|
def with_role_and_shard(role, shard, prevent_writes)
|
||||||
prevent_writes = true if role == reading_role
|
prevent_writes = true if role == reading_role
|
||||||
|
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
with_handler(role.to_sym) do
|
with_handler(role.to_sym) do
|
||||||
connection_handler.while_preventing_writes(prevent_writes) do
|
connection_handler.while_preventing_writes(prevent_writes) do
|
||||||
self.connected_to_stack << { shard: shard, klasses: [self] }
|
self.connected_to_stack << { shard: shard, klasses: [self] }
|
||||||
|
|
|
@ -164,8 +164,6 @@ module ActiveRecord
|
||||||
|
|
||||||
class_attribute :default_shard, instance_writer: false
|
class_attribute :default_shard, instance_writer: false
|
||||||
|
|
||||||
mattr_accessor :legacy_connection_handling, instance_writer: false, default: true
|
|
||||||
|
|
||||||
mattr_accessor :application_record_class, instance_accessor: false, default: nil
|
mattr_accessor :application_record_class, instance_accessor: false, default: nil
|
||||||
|
|
||||||
# Sets the async_query_executor for an application. By default the thread pool executor
|
# Sets the async_query_executor for an application. By default the thread pool executor
|
||||||
|
@ -225,7 +223,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.connection_handlers
|
def self.connection_handlers
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
else
|
else
|
||||||
raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers."
|
raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers."
|
||||||
end
|
end
|
||||||
|
@ -234,7 +232,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.connection_handlers=(handlers)
|
def self.connection_handlers=(handlers)
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
ActiveSupport::Deprecation.warn(<<~MSG)
|
ActiveSupport::Deprecation.warn(<<~MSG)
|
||||||
Using legacy connection handling is deprecated. Please set
|
Using legacy connection handling is deprecated. Please set
|
||||||
`legacy_connection_handling` to `false` in your application.
|
`legacy_connection_handling` to `false` in your application.
|
||||||
|
@ -270,7 +268,7 @@ module ActiveRecord
|
||||||
# ActiveRecord::Base.current_role #=> :reading
|
# ActiveRecord::Base.current_role #=> :reading
|
||||||
# end
|
# end
|
||||||
def self.current_role
|
def self.current_role
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
connection_handlers.key(connection_handler) || default_role
|
connection_handlers.key(connection_handler) || default_role
|
||||||
else
|
else
|
||||||
connected_to_stack.reverse_each do |hash|
|
connected_to_stack.reverse_each do |hash|
|
||||||
|
@ -311,7 +309,7 @@ module ActiveRecord
|
||||||
# ActiveRecord::Base.current_preventing_writes #=> false
|
# ActiveRecord::Base.current_preventing_writes #=> false
|
||||||
# end
|
# end
|
||||||
def self.current_preventing_writes
|
def self.current_preventing_writes
|
||||||
if legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
connection_handler.prevent_writes
|
connection_handler.prevent_writes
|
||||||
else
|
else
|
||||||
connected_to_stack.reverse_each do |hash|
|
connected_to_stack.reverse_each do |hash|
|
||||||
|
|
|
@ -28,7 +28,7 @@ module ActiveRecord
|
||||||
def self.run
|
def self.run
|
||||||
pools = []
|
pools = []
|
||||||
|
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.connection_handlers.each do |key, handler|
|
ActiveRecord::Base.connection_handlers.each do |key, handler|
|
||||||
pools.concat(handler.connection_pool_list.reject { |p| p.query_cache_enabled }.each { |p| p.enable_query_cache! })
|
pools.concat(handler.connection_pool_list.reject { |p| p.query_cache_enabled }.each { |p| p.enable_query_cache! })
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,7 @@ module ActiveRecord
|
||||||
def self.complete(pools)
|
def self.complete(pools)
|
||||||
pools.each { |pool| pool.disable_query_cache! }
|
pools.each { |pool| pool.disable_query_cache! }
|
||||||
|
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.connection_handlers.each do |_, handler|
|
ActiveRecord::Base.connection_handlers.each do |_, handler|
|
||||||
handler.connection_pool_list.each do |pool|
|
handler.connection_pool_list.each do |pool|
|
||||||
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
|
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
|
||||||
|
|
|
@ -200,11 +200,22 @@ To keep using the current cache store, you can turn off cache versioning entirel
|
||||||
end
|
end
|
||||||
|
|
||||||
initializer "active_record.set_configs" do |app|
|
initializer "active_record.set_configs" do |app|
|
||||||
ActiveSupport.on_load(:active_record) do
|
|
||||||
configs = app.config.active_record
|
configs = app.config.active_record
|
||||||
|
|
||||||
configs.each do |k, v|
|
configs.each do |k, v|
|
||||||
send "#{k}=", v if k != :encryption
|
next if k == :encryption
|
||||||
|
setter = "#{k}="
|
||||||
|
if ActiveRecord.respond_to?(setter)
|
||||||
|
ActiveRecord.send(setter, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveSupport.on_load(:active_record) do
|
||||||
|
configs.each do |k, v|
|
||||||
|
next if k == :encryption
|
||||||
|
setter = "#{k}="
|
||||||
|
next if ActiveRecord.respond_to?(setter)
|
||||||
|
send(setter, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -213,7 +224,7 @@ To keep using the current cache store, you can turn off cache versioning entirel
|
||||||
# and then establishes the connection.
|
# and then establishes the connection.
|
||||||
initializer "active_record.initialize_database" do
|
initializer "active_record.initialize_database" do
|
||||||
ActiveSupport.on_load(:active_record) do
|
ActiveSupport.on_load(:active_record) do
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
self.connection_handlers = { writing_role => ActiveRecord::Base.default_connection_handler }
|
self.connection_handlers = { writing_role => ActiveRecord::Base.default_connection_handler }
|
||||||
end
|
end
|
||||||
self.configurations = Rails.application.config.database_configuration
|
self.configurations = Rails.application.config.database_configuration
|
||||||
|
|
|
@ -193,7 +193,7 @@ module ActiveRecord
|
||||||
# need to share a connection pool so that the reading connection
|
# need to share a connection pool so that the reading connection
|
||||||
# can see data in the open transaction on the writing connection.
|
# can see data in the open transaction on the writing connection.
|
||||||
def setup_shared_connection_pool
|
def setup_shared_connection_pool
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
writing_handler = ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
|
writing_handler = ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
|
||||||
|
|
||||||
ActiveRecord::Base.connection_handlers.values.each do |handler|
|
ActiveRecord::Base.connection_handlers.values.each do |handler|
|
||||||
|
@ -236,7 +236,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown_shared_connection_pool
|
def teardown_shared_connection_pool
|
||||||
if ActiveRecord::Base.legacy_connection_handling
|
if ActiveRecord.legacy_connection_handling
|
||||||
@legacy_saved_pool_configs.each_pair do |handler, names|
|
@legacy_saved_pool_configs.each_pair do |handler, names|
|
||||||
names.each_pair do |name, shards|
|
names.each_pair do |name, shards|
|
||||||
shards.each_pair do |shard_name, pool_config|
|
shards.each_pair do |shard_name, pool_config|
|
||||||
|
|
|
@ -127,8 +127,8 @@ module ActiveRecord
|
||||||
|
|
||||||
class AdapterPreventWritesLegacyTest < ActiveRecord::TestCase
|
class AdapterPreventWritesLegacyTest < ActiveRecord::TestCase
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
@connection = ActiveRecord::Base.connection
|
@connection = ActiveRecord::Base.connection
|
||||||
@connection_handler = ActiveRecord::Base.connection_handler
|
@connection_handler = ActiveRecord::Base.connection_handler
|
||||||
|
@ -136,7 +136,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = @old_value
|
ActiveRecord.legacy_connection_handling = @old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_preventing_writes_predicate_legacy
|
def test_preventing_writes_predicate_legacy
|
||||||
|
|
|
@ -105,15 +105,15 @@ class Mysql2AdapterPreventWritesLegacyTest < ActiveRecord::Mysql2TestCase
|
||||||
include DdlHelper
|
include DdlHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
@conn = ActiveRecord::Base.connection
|
@conn = ActiveRecord::Base.connection
|
||||||
@connection_handler = ActiveRecord::Base.connection_handler
|
@connection_handler = ActiveRecord::Base.connection_handler
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
ActiveRecord::Base.legacy_connection_handling = @old_value
|
ActiveRecord.legacy_connection_handling = @old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_errors_when_an_insert_query_is_called_while_preventing_writes
|
def test_errors_when_an_insert_query_is_called_while_preventing_writes
|
||||||
|
|
|
@ -106,15 +106,15 @@ module ActiveRecord
|
||||||
include ConnectionHelper
|
include ConnectionHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
@connection = ActiveRecord::Base.connection
|
@connection = ActiveRecord::Base.connection
|
||||||
@connection_handler = ActiveRecord::Base.connection_handler
|
@connection_handler = ActiveRecord::Base.connection_handler
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
ActiveRecord::Base.legacy_connection_handling = @old_value
|
ActiveRecord.legacy_connection_handling = @old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_errors_when_an_insert_query_is_called_while_preventing_writes
|
def test_errors_when_an_insert_query_is_called_while_preventing_writes
|
||||||
|
|
|
@ -95,8 +95,8 @@ module ActiveRecord
|
||||||
self.use_transactional_tests = false
|
self.use_transactional_tests = false
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
@conn = ActiveRecord::Base.connection
|
@conn = ActiveRecord::Base.connection
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
ActiveRecord::Base.legacy_connection_handling = @old_value
|
ActiveRecord.legacy_connection_handling = @old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_errors_when_an_insert_query_is_called_while_preventing_writes
|
def test_errors_when_an_insert_query_is_called_while_preventing_writes
|
||||||
|
|
|
@ -97,15 +97,15 @@ class BasePreventWritesTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
class BasePreventWritesLegacyTest < ActiveRecord::TestCase
|
class BasePreventWritesLegacyTest < ActiveRecord::TestCase
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
ActiveRecord::Base.establish_connection :arunit
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
ARUnit2Model.establish_connection :arunit2
|
ARUnit2Model.establish_connection :arunit2
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = @old_value
|
ActiveRecord.legacy_connection_handling = @old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
if !in_memory_db?
|
if !in_memory_db?
|
||||||
|
|
|
@ -1682,8 +1682,8 @@ class BasicsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cannot call connected_to on subclasses of ActiveRecord::Base with legacy connection handling" do
|
test "cannot call connected_to on subclasses of ActiveRecord::Base with legacy connection handling" do
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
error = assert_raises(NotImplementedError) do
|
error = assert_raises(NotImplementedError) do
|
||||||
Bird.connected_to(role: :reading) { }
|
Bird.connected_to(role: :reading) { }
|
||||||
|
@ -1692,7 +1692,7 @@ class BasicsTest < ActiveRecord::TestCase
|
||||||
assert_equal "`connected_to` can only be called on ActiveRecord::Base with legacy connection handling.", error.message
|
assert_equal "`connected_to` can only be called on ActiveRecord::Base with legacy connection handling.", error.message
|
||||||
ensure
|
ensure
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cannot call connected_to with role and shard on non-abstract classes" do
|
test "cannot call connected_to with role and shard on non-abstract classes" do
|
||||||
|
@ -1744,25 +1744,25 @@ class BasicsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "#connecting_to doesn't work with legacy connection handling" do
|
test "#connecting_to doesn't work with legacy connection handling" do
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
assert_raises NotImplementedError do
|
assert_raises NotImplementedError do
|
||||||
SecondAbstractClass.connecting_to(role: :writing, prevent_writes: true)
|
SecondAbstractClass.connecting_to(role: :writing, prevent_writes: true)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
test "#connected_to_many doesn't work with legacy connection handling" do
|
test "#connected_to_many doesn't work with legacy connection handling" do
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
assert_raises NotImplementedError do
|
assert_raises NotImplementedError do
|
||||||
ActiveRecord::Base.connected_to_many([SecondAbstractClass], role: :writing)
|
ActiveRecord::Base.connected_to_many([SecondAbstractClass], role: :writing)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
test "#connected_to_many cannot be called on anything but ActiveRecord::Base" do
|
test "#connected_to_many cannot be called on anything but ActiveRecord::Base" do
|
||||||
|
|
|
@ -11,8 +11,8 @@ module ActiveRecord
|
||||||
fixtures :people
|
fixtures :people
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = @old_value
|
ActiveRecord.legacy_connection_handling = @old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
class SecondaryBase < ActiveRecord::Base
|
class SecondaryBase < ActiveRecord::Base
|
||||||
|
|
|
@ -11,8 +11,8 @@ module ActiveRecord
|
||||||
fixtures :people
|
fixtures :people
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@legacy_setting = ActiveRecord::Base.legacy_connection_handling
|
@legacy_setting = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = @legacy_setting
|
ActiveRecord.legacy_connection_handling = @legacy_setting
|
||||||
end
|
end
|
||||||
|
|
||||||
unless in_memory_db?
|
unless in_memory_db?
|
||||||
|
|
|
@ -1541,8 +1541,8 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
||||||
fixtures :dogs
|
fixtures :dogs
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@old_value = ActiveRecord::Base.legacy_connection_handling
|
@old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
@old_handler = ActiveRecord::Base.connection_handler
|
@old_handler = ActiveRecord::Base.connection_handler
|
||||||
@prev_configs, ActiveRecord::Base.configurations = ActiveRecord::Base.configurations, config
|
@prev_configs, ActiveRecord::Base.configurations = ActiveRecord::Base.configurations, config
|
||||||
|
@ -1565,7 +1565,7 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
||||||
ActiveRecord::Base.configurations = @prev_configs
|
ActiveRecord::Base.configurations = @prev_configs
|
||||||
ActiveRecord::Base.connection_handler = @old_handler
|
ActiveRecord::Base.connection_handler = @old_handler
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = false
|
ActiveRecord.legacy_connection_handling = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uses_writing_connection_for_fixtures
|
def test_uses_writing_connection_for_fixtures
|
||||||
|
|
|
@ -75,8 +75,8 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_query_cache_is_applied_to_legacy_connections_in_all_handlers
|
def test_query_cache_is_applied_to_legacy_connections_in_all_handlers
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
ActiveRecord::Base.connection_handlers = {
|
ActiveRecord::Base.connection_handlers = {
|
||||||
|
@ -101,7 +101,7 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
mw.call({})
|
mw.call({})
|
||||||
ensure
|
ensure
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_query_cache_is_applied_to_all_connections
|
def test_query_cache_is_applied_to_all_connections
|
||||||
|
@ -126,8 +126,8 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
if Process.respond_to?(:fork) && !in_memory_db?
|
if Process.respond_to?(:fork) && !in_memory_db?
|
||||||
def test_query_cache_with_multiple_handlers_and_forked_processes_legacy_handling
|
def test_query_cache_with_multiple_handlers_and_forked_processes_legacy_handling
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
ActiveRecord::Base.connection_handlers = {
|
ActiveRecord::Base.connection_handlers = {
|
||||||
|
@ -190,7 +190,7 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
rd.close
|
rd.close
|
||||||
ensure
|
ensure
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_query_cache_with_forked_processes
|
def test_query_cache_with_forked_processes
|
||||||
|
@ -665,8 +665,8 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_clear_query_cache_is_called_on_all_legacy_connections
|
def test_clear_query_cache_is_called_on_all_legacy_connections
|
||||||
skip "with in memory db, reading role won't be able to see database on writing role" if in_memory_db?
|
skip "with in memory db, reading role won't be able to see database on writing role" if in_memory_db?
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
assert_deprecated do
|
assert_deprecated do
|
||||||
ActiveRecord::Base.connection_handlers = {
|
ActiveRecord::Base.connection_handlers = {
|
||||||
|
@ -704,7 +704,7 @@ class QueryCacheTest < ActiveRecord::TestCase
|
||||||
ensure
|
ensure
|
||||||
unless in_memory_db?
|
unless in_memory_db?
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ class TestFixturesTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
unless in_memory_db?
|
unless in_memory_db?
|
||||||
def test_doesnt_rely_on_active_support_test_case_specific_methods_with_legacy_connection_handling
|
def test_doesnt_rely_on_active_support_test_case_specific_methods_with_legacy_connection_handling
|
||||||
old_value = ActiveRecord::Base.legacy_connection_handling
|
old_value = ActiveRecord.legacy_connection_handling
|
||||||
ActiveRecord::Base.legacy_connection_handling = true
|
ActiveRecord.legacy_connection_handling = true
|
||||||
|
|
||||||
tmp_dir = Dir.mktmpdir
|
tmp_dir = Dir.mktmpdir
|
||||||
File.write(File.join(tmp_dir, "zines.yml"), <<~YML)
|
File.write(File.join(tmp_dir, "zines.yml"), <<~YML)
|
||||||
|
@ -59,7 +59,7 @@ class TestFixturesTest < ActiveRecord::TestCase
|
||||||
clean_up_legacy_connection_handlers
|
clean_up_legacy_connection_handlers
|
||||||
ActiveRecord::Base.connection_handler = old_handler
|
ActiveRecord::Base.connection_handler = old_handler
|
||||||
FileUtils.rm_r(tmp_dir)
|
FileUtils.rm_r(tmp_dir)
|
||||||
ActiveRecord::Base.legacy_connection_handling = old_value
|
ActiveRecord.legacy_connection_handling = old_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_doesnt_rely_on_active_support_test_case_specific_methods
|
def test_doesnt_rely_on_active_support_test_case_specific_methods
|
||||||
|
|
|
@ -19,7 +19,7 @@ module ARTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.connect
|
def self.connect
|
||||||
ActiveRecord::Base.legacy_connection_handling = false
|
ActiveRecord.legacy_connection_handling = false
|
||||||
ActiveRecord::Base.async_query_executor = :global_thread_pool
|
ActiveRecord::Base.async_query_executor = :global_thread_pool
|
||||||
puts "Using #{connection_name}"
|
puts "Using #{connection_name}"
|
||||||
ActiveRecord::Base.logger = ActiveSupport::Logger.new("debug.log", 0, 100 * 1024 * 1024)
|
ActiveRecord::Base.logger = ActiveSupport::Logger.new("debug.log", 0, 100 * 1024 * 1024)
|
||||||
|
|
Loading…
Reference in a new issue