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:
|
connection.columns(table).each do |column| |
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!
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:
It seems that a couple of places in
active_record_doctorassume 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:
active_record_doctor/lib/active_record_doctor/detectors/missing_non_null_constraint.rb
Line 35 in f3b8ba5
uses
connection, which raises an error along the lines of:A possible fix might be to use
models.first.columnsinstead ofconnection.columns(table)so that the per-model connection is used?Similarly, this line has the same issue:
active_record_doctor/lib/active_record_doctor/detectors/base.rb
Line 218 in f3b8ba5
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
connectionwithout reference to a particularmodelinstance.Thanks!