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

Error when listing columns for model backed by different DB #149

Open
owst opened this issue Aug 25, 2023 · 6 comments
Open

Error when listing columns for model backed by different DB #149

owst opened this issue Aug 25, 2023 · 6 comments

Comments

@owst
Copy link

owst commented Aug 25, 2023

We have a couple of models that are backed by a different DB to the majority of models in our app. A rough example is something like this:

class MainDBThings < ApplicationRecord
end
class ExternalDBThings < ApplicationRecord
  establish_connection :external_db
end

It seems that a couple of places in active_record_doctor assume that all tables can be accessed from a connection to a single DB (ActiveRecord::Base.connection); when the "different DB" table names are accessed, a "table missing" error is raised because the connection used is to the wrong DB.

For example, this line:

uses connection, which raises an error along the lines of:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "ExternalDBThings" does not exist

A possible fix might be to use models.first.columns instead of connection.columns(table) so that the per-model connection is used?

Similarly, this line has the same issue:

connection.columns(model.table_name).each do |column|

I'm happy to have a stab at a PR for this, but would like some guidance as to any thoughts or suggested approaches before I start. I expect the fix will be to not use connection without reference to a particular model instance.

Thanks!

@fatkodima
Copy link
Contributor

fatkodima commented Oct 8, 2023

Suggested changes will solve this issue, but this gem still do not have proper support for multiple databases, see #63.

Please, do open a PR.

@gregnavis
Copy link
Owner

Thanks for opening the issue, @owst! I'm working hard on adding support for multi-database systems, so expect an update soon. Would you be willing to test a release candidate?

@owst
Copy link
Author

owst commented Oct 16, 2023

Sure thing @gregnavis, that sounds good - thanks!

@brunoarueira
Copy link

@gregnavis I would like to test a release candidate too, call me in! Btw, thanks for this gem 😃

@owst
Copy link
Author

owst commented Feb 28, 2024

Hi @gregnavis I just came across this issue again preventing us from upgrading active_record_doctor, have you managed to make any progress on multi-DB support and do you maybe have a release candidate to test?

@gregnavis
Copy link
Owner

@owst, actually, yes, I've made some progress, but it's not done yet. I released transient_record 2.0 that supports multiple databases. That was a prerequisite for adding multi-database test cases to active_record_doctor.

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