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

Not ready to work with multiple databases #48

Open
Koilanetroc opened this issue Sep 13, 2022 · 4 comments
Open

Not ready to work with multiple databases #48

Koilanetroc opened this issue Sep 13, 2022 · 4 comments

Comments

@Koilanetroc
Copy link

As I can see in source prosopite uses ActiveRecord::Base to define database adapter. If you have multiple databases you probably have multiple successors of ApplicationRecord where each of them uses different database. When prosopite uses ActiveRecord::Base it will always get adapter of primary database which is not correct. As a result, gem just fails when encounters active record queries from not primary database and can't be used at all.

Not sure if it's easy fix, but maybe it is worth mentioning it in docs?

@technicalpickles
Copy link
Contributor

Adding a permalink copy, since the line has changed:

if ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')

It looks like this code is only using it to determine if it's mysql or postgresql.

We do use prosopite with multiple database, but they are all the same kind (mysql).

@technicalpickles
Copy link
Contributor

It looks like we use ActiveSupport::Notification to subscribe to sql.active_record:

prosopite/lib/prosopite.rb

Lines 215 to 218 in 5d1fbc1

ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, _, _, _, data|
sql, name = data[:sql], data[:name]
if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil? && !ignore_query?(sql)

Pulling up the docs, it looks like one of the pieces of data that comes across is the Connection object. That means it should be feasible to save details about the connection's database type with the sql queries, but does require changing some of the way data is saved about the queries.

@bf4
Copy link

bf4 commented Jun 29, 2023

test_prof uses ActiveRecord::Base.connection_handler.connection_pool_list which gets a list of the connection classes. might be a useful strategy here. we use multiple dbs but I don't think we've seen issues.

e.g. to get a list of all my connection classes I can

ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection_class).map(&:name).sort

@jasonkarns
Copy link

Is there any workaround for using prosopite with multiple databases that aren't all the same? We use both mysql and postgres and were hoping to start using prosopite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants