gregnavis / active_record_doctor

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

Idea: For Rails 7.1, error when there are foreign keys with `validate: false` #169

Closed jdufresne closed 2 months ago

jdufresne commented 9 months ago

Rails 7.1 added the feature to record validate in schema.rb, see upstream PR: https://github.com/rails/rails/pull/46339

My proposal is that active_record_doctor emits an error when validate: false exists. In my experience, this is normally a "code smell" that something went wrong with migrations and they are incomplete.

I most often use validate: false on the advice of strong_migrations for a zero downtime schema change, but the validation is resolved once all migration riles run. Their docs are at: https://github.com/ankane/strong_migrations#adding-a-foreign-key

fatkodima commented 9 months ago

These will be false positives most of the time, because the next step in migrations will be validation for these and the validate will be removed then. So it will stay not a long time in the schema.rb and lead to violations and disabling of it in the gems config file.

jdufresne commented 9 months ago

These will be false positives most of the time, because the next step in migrations will be validation for these and the validate will be removed then. So it will stay not a long time in the schema.rb and lead to violations and disabling of it in the gems config file.

In my experience, these steps come together within the same PR, just as separate migration files. So at CI time, there will not be a false positive.