aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-18 08:38:10 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-12-18 08:38:10 -0800
commite4003adff93a1379a5e632f7e199c61bf34c293d (patch)
treea59deb84ea5ca4fb4ed257d35afe47eb64f04858
parent15c40b2ef51120974edc626106de69faa53dfc3f (diff)
parent9bb27f7ffe3eb732df737e477cd8fc25e007f77b (diff)
downloadrails-e4003adff93a1379a5e632f7e199c61bf34c293d.tar.gz
rails-e4003adff93a1379a5e632f7e199c61bf34c293d.tar.bz2
rails-e4003adff93a1379a5e632f7e199c61bf34c293d.zip
Merge pull request #8548 from garysweaver/postgresql_fallback_to_disable_user_triggers
fix #5523: postgresql adapter to disable user triggers in disable_referential_integrity
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb16
2 files changed, 17 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index e7d3b529fe..25a02d76a4 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Add ability for postgresql adapter to disable user triggers in disable_referential_integrity.
+ Fix #5523
+
+ *Gary S. Weaver*
+
* Added support for `validates_uniqueness_of` in PostgreSQL array columns.
Fixes #8075.
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb b/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
index 16da3ea732..bc775394a6 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
@@ -7,13 +7,21 @@ module ActiveRecord
end
def disable_referential_integrity #:nodoc:
- if supports_disable_referential_integrity? then
- execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
+ if supports_disable_referential_integrity?
+ begin
+ execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
+ rescue
+ execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER USER" }.join(";"))
+ end
end
yield
ensure
- if supports_disable_referential_integrity? then
- execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
+ if supports_disable_referential_integrity?
+ begin
+ execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
+ rescue
+ execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER USER" }.join(";"))
+ end
end
end
end