active_record_doctor
active_record_doctor copied to clipboard
Ignore or warn about models referencing non-existent internal Rails tables by default
On Rails 7 (and probably on Rails 6 too) with new app I will get following errors, when I run bundle exec rails active_record_doctor:undefined_table_references
:
ActionMailbox::InboundEmail references a non-existent table or view named action_mailbox_inbound_emails
ActiveStorage::VariantRecord references a non-existent table or view named active_storage_variant_records
ActiveStorage::Blob references a non-existent table or view named active_storage_blobs
ActiveStorage::Attachment references a non-existent table or view named active_storage_attachments
ActionText::RichText references a non-existent table or view named action_text_rich_texts
ActionText::EncryptedRichText references a non-existent table or view named action_text_rich_texts
I think it is intended, but in many cases it should not be an error, because most new apps are not using those features a long time, if ever at all (e.g. InboundEmail
).
The documentation says that those tables are ignored by default for other tasks.
Maybe it is too much to ignore them in this case, then it should be only a warning?! Probably it is hard to detect, if those models are used and only in this case to produce an error?
The documentation says that those tables are ignored by default for other tasks.
Personally, I think that was not the best idea to ignore them by default, because it is possible to miss some flaws even for them (despite being developed by smart people etc, maybe you modified them by yourself, who knows?), for example, duplicate indexes or integer
primary keys. I would prefer to have none of the tables ignored by default and the user should himself configure those if he decides to.
As for mentioned models, the same thought.
As an alternative, if you are not using active_storage
, action_text
, etc you can remove them from your application, reducing its size, by adding separate gems into Gemfile
instead of gem "rails"
and requiring specific gems in config/application.rb
instead of require "rails/all"
. See https://github.com/rails/rails/blob/main/railties/lib/rails/all.rb
And those warnings will disappear.
As I said, "Maybe it is too much to ignore them". And I am fine with the ideas like "And those warnings will disappear.". When it would be only a warning. But it is an error, stopping execution of following tasks.
Yes, I mean "errors". They will disappear.
I know what you mean. But in the most cases it still produces error on new projects, before I start to use those Models and features. With warnings it would be OK, because all following tasks would run as they should.