rsim/oracle-enhanced

Second DB connection has same connection_db_config (by object ID) as first DB connection

Closed this issue · 0 comments

Update: Some model classes are shared and were in a gem. As such, the gem also contains application_record.rb and the class for the secondary DB. The model class for the secondary DB is defined in the gem, and it does not pick up the configuration / definition in the file in the Rails app itself. This is not an issue with the adapter.

This may be more of an enhancement request than a bug report. I plan to look at the gem's source to see what is going on, if only one connection and connection configuration can be used.

Steps to reproduce

Please refer https://github.com/rsim/oracle-enhanced/tree/master/guides/bug_report_templates
to create an executable test case

class FirstDbBase < ActiveRecord::Base
self.abstract_class = true
establish_connection FIRST_DB
end

FIRST_DB is loaded from YAML config. (In case it matters, in the example that repeats the first config in the 2nd connection, this FirstDbBase is the usual ApplicationRecord class. Configuration is loaded automatically from database.yml for the first, and from another .yml file in an initializer for the second.)

class SomethingInFirstDb < FirstDbBase ... end

Same for SECOND_DB and SomethingInSecondDb < SecondDbBase. Configuration is loaded from YAML in an initializer.

Expected behavior

Tell us what should happen

puts SomethingInFirstDb.connection_db_config
puts SomethingInSecondDb.connection_db_config

Expect to see two different connection configurations, or an exception when establish_connection is called for the second connection.

Actual behavior

Tell us what happens instead

Connection configuration is the same object ID. Second connection is also to the first database.

SQL Server adapter returns two different configurations, as expected. (In case it matters, both of these are loaded from their own .yml files in initializers.)

I have to wonder if this difference has anything to do with connection config loaded automatically from database.yml, versus the second connection with the same Oracle adapter also picking up the same config. I should be able to test this and/or see what ActiveRecord is doing based on code.

System configuration

Rails version:
6.1.4.1

Oracle enhanced adapter version:
6.1.4

Ruby version:
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

Oracle Database version:
both 19c