Skip to content
Browse files

[postgres] disable_referential_integrity on USER level (AR-4.0 compat)

  • Loading branch information...
1 parent 888bb1b commit 1ccbe8219b45481a02f28e88bb1f46c805b3aedf @kares kares committed Mar 21, 2013
Showing with 18 additions and 2 deletions.
  1. +18 −2 lib/arjdbc/postgresql/adapter.rb
View
20 lib/arjdbc/postgresql/adapter.rb
@@ -1001,11 +1001,27 @@ def quoted_date(value) #:nodoc:
result
end
+ def supports_disable_referential_integrity? # :nodoc:
+ true
+ end
+
def disable_referential_integrity # :nodoc:
- 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
- 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
def rename_table(table_name, new_name)

0 comments on commit 1ccbe82

Please sign in to comment.
Something went wrong with that request. Please try again.