#8498 postgres_adapter fix for disable_referential_integrity

Please review this patch for postgres adapter’s referential_integrity.rb in Rails master and 3.2.9 and let me know what you think. We are using it via an initializer (monkey patching the adapter directly vs. in module):
https://github.com/rails/rails/pull/8498

Fixes this issue also seen by others in Foreigner: https://github.com/matthuhiggins/foreigner/issues/61

Problem that it resolves:

/…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in async_exec': PG::Error: ERROR: permission denied: "RI_ConstraintTrigger_1234" is a system trigger (ActiveRecord::StatementInvalid) : (SQL here) from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in block in execute’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:in block in log' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in instrument’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:in log' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in execute’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:528:in ensure in disable_referential_integrity' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/activerecord-3.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:528:in disable_referential_integrity’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/database_cleaner-0.9.1/lib/database_cleaner/active_record/deletion.rb:57:in clean' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/database_cleaner-0.9.1/lib/database_cleaner/base.rb:39:in clean_with’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/database_cleaner-0.9.1/lib/database_cleaner/configuration.rb:85:in block in clean_with' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/database_cleaner-0.9.1/lib/database_cleaner/configuration.rb:85:in each’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/database_cleaner-0.9.1/lib/database_cleaner/configuration.rb:85:in clean_with' from /.../jenkins/jobs/my_application-some_branch/workspace/spec/support/database_cleaner.rb:8:in block (2 levels) in <top (required)>’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/hooks.rb:23:in instance_eval' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/hooks.rb:23:in run’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/hooks.rb:72:in block in run' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/hooks.rb:72:in each’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/hooks.rb:72:in run' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/hooks.rb:424:in run_hook’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/command_line.rb:27:in block in run' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/reporter.rb:34:in report’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/command_line.rb:25:in run' from /.../jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/runner.rb:80:in run’
from /…/jenkins/.rvm/gems/ruby-1.9.3-p194@my_application/gems/rspec-core-2.12.1/lib/rspec/core/runner.rb:17:in `block in autorun’

Thanks in advance for your time.

New pull request: https://github.com/rails/rails/pull/8548

To fix: https://github.com/rails/rails/issues/5523

Git is a fairweather friend.