Add a cop to prevent use of `disable_referential_integrity`
💥 Problem
disable_referential_integrity allows a developer to disable all triggers on all tables in the database. This can lead to data consistency problems as described in this PostgreSQL thread.
There are two problems with this method:
- Triggers are disabled for all tables even though we may only need to disable them for one table
- The disabling of triggers occurs in a separate database transaction from the query, which presents an opportunity for rollback problem.
💡 Solution
If triggers need to be disabled, we should do so on the specific table, or optimally on the specific constraint needed.
We should add a rubocop rule to prevent use of disable_referential_integrity.
It is generally used as:
ActiveRecord::Base.connection.disable_referential_integrity do
# query
end
Related
#358606 (closed) removes existing usage of this method.
Edited by Steve Abrams