-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Labels
new detectorA detector for a new kind of problem.A detector for a new kind of problem.
Description
Hi there @gregnavis, thanks for this gem! I've got a custom detector I'm running in our codebase to detect when a table is no longer referenced by a model. Is that something that would make sense to PR back to ActiveRecordDoctor, or is it outside of what you'd consider its core purpose?
For us, it's helpful to remember to drop a table after the ruby code using it has been removed, because the contents of the table are persisted in our data warehouse and it's safe to drop the production version of the table. However, the potential gotchas for others would be:
- If you don't back up the data elsewhere, you may never want to drop a table, even if you phase out the model representing it
- The detector will flag a problem on the branch that removes the ruby code, but you shouldn't actually drop the table until that branch has been deployed, so you should always add it to the "ignored" list temporarily (or else do something dangerous).
It could also potentially be added to the gem but disabled by default with the caveats above documented.
Let me know what you think, again I'm happy to PR it. It's really just doing this:
each_table(except: config(:ignore_tables)) do |table|
matching_model = ActiveRecord::Base.descendants.find do |model|
model.table_name == table
end
problem!(table:) if matching_model.nil?
endgregnavis
Metadata
Metadata
Assignees
Labels
new detectorA detector for a new kind of problem.A detector for a new kind of problem.