gregnavis / active_record_doctor

Identify database issues before they hit production.
MIT License
1.76k stars 55 forks source link

`MissingForeignKeys` detector assumptions #94

Open fatkodima opened 2 years ago

fatkodima commented 2 years ago

The checker makes an assumption that foreign-key like columns should be in the form of ..._id.

It can:

  1. lead to false positives, when some table have some column ending with _id which is not a reference to other table, but, for example, some id from the external resource (users.stripe_id).
  2. miss some custom named foreign keys: belongs_to :user, foreign_key: :user_key

I think, what should be really checked are models having non-polymorphic belongs_to associations without foreign keys.

Checking only models would make it easier to also ignore the case, when underlying models belong to different databases.