1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test
eileencodes b74fbe4e51
Deprecate "primary" as a connection_specification_name for ActiveRecord::Base
As multiple databases have evolved it's becoming more and more
confusing that we have a `connection_specification_name` that defaults
to "primary" and a `spec_name` on the database objects that defaults to
"primary" (my bad).

Even more confusing is that we use the class name for all
non-ActiveRecord::Base abstract classes that establish connections. For
example connections established on `class MyOtherDatabaseModel <
ApplicationRecord` will use `"MyOtherDatabaseModel"` as it's connection
specification name while `ActiveRecord::Base` uses `"primary"`.

This PR deprecates the use of the name `"primary"` as the
`connection_specification_name` for `ActiveRecord::Base` in favor of
using `"ActiveRecord::Base"`.

In this PR the following is true:

* If `handler.establish_connection(:primary)` is called, `"primary"`
will not throw a deprecation warning and can still be used for the
`connection_specification_name`. This also fixes a bug where using this
method to establish a connection could accidentally overwrite the actual
`ActiveRecord::Base` connection IF that connection was not using a
configuration named `:primary`.
* Calling `handler.retrieve_connection "primary"` when
`handler.establish_connection :primary` has never been called will
return the connection for `ActiveRecord::Base` and throw a deprecation
warning.
* Calling `handler.remove_connection "primary"` when
`handler.establish_connection :primary` has never been called will
remove the connection for `ActiveRecord::Base` and throw a deprecation
warning.

See #38179 for details on more motivations for this change.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-01-08 16:49:41 -05:00
..
active_record/connection_adapters Deduplicate various Active Record schema cache structures 2019-06-03 13:31:42 +02:00
assets
cases Deprecate "primary" as a connection_specification_name for ActiveRecord::Base 2020-01-08 16:49:41 -05:00
fixtures Allow AR::Enum definitions with boolean values 2019-12-24 07:05:42 -10:00
migrations
models Avoid extraneous preloading when loading across has_one associations 2020-01-08 08:14:04 +13:00
schema Add ActiveRecord::Validations::NumericalityValidator 2020-01-06 19:01:29 -05:00
support Rename a test method to not conflict with a deprecated method 2019-12-17 12:35:15 -05:00
config.example.yml
config.rb