Skip to content
  • eileencodes's avatar
    b74fbe4e
    Deprecate "primary" as a connection_specification_name for ActiveRecord::Base · b74fbe4e
    eileencodes authored
    
    
    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: default avatarJohn Crepezzi <john.crepezzi@gmail.com>
    b74fbe4e
    Deprecate "primary" as a connection_specification_name for ActiveRecord::Base
    eileencodes authored
    
    
    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: default avatarJohn Crepezzi <john.crepezzi@gmail.com>
Loading