Fix establishing connections for models with custom connection specification names
We have an internal engine whose models, for backwards compatibility with older Rails versions, override #connection_specification_name to connect to a shared DB rather than using Rails 6 multi-DB support. b8fc0150 changed ActiveRecord::ConnectionAdapters::ConnectionPool#retrieve_connection_pool to pass ActiveRecord::DatabaseConfigurations::DatabaseConfig#config_hash to #establish_connection where it previously passed ActiveRecord::ConnectionAdapters::ConnectionSpecification#to_hash. But DatabaseConfig#config_hash does not include the specification name, so #establish_connection falls back to `"primary"`. The host app's primary DB connections and our engine's shared DB connections get mixed in the same pool as a result. Engine models will sometimes erroneously check out app DB connections and app models will sometimes check out engine DB connections. To fix, we merge the connection specification name into the DB config hash before passing it into ConnectionPool#establish_connection.
Showing
想要评论请 注册 或 登录