Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate "primary" as a connection_specification_name for ActiveRecord::Base #38190

Conversation

@eileencodes
Copy link
Member

eileencodes commented Jan 8, 2020

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

@rails-bot rails-bot bot added the activerecord label Jan 8, 2020
@eileencodes eileencodes added this to the 6.1.0 milestone Jan 8, 2020
@eileencodes eileencodes force-pushed the seejohnrun:deprecate-primary-as-connection_specification_name branch 2 times, most recently from b11eeb6 to 3daae24 Jan 8, 2020
…rd::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>
@eileencodes eileencodes force-pushed the seejohnrun:deprecate-primary-as-connection_specification_name branch from 3daae24 to b74fbe4 Jan 8, 2020
@eileencodes eileencodes merged commit 4a477c0 into rails:master Jan 9, 2020
2 checks passed
2 checks passed
build
Details
buildkite/rails Build #66292 passed (13 minutes, 22 seconds)
Details
@eileencodes eileencodes deleted the seejohnrun:deprecate-primary-as-connection_specification_name branch Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.