diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-02-01 22:04:58 +0000 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-02-01 22:04:58 +0000 |
commit | ea04caec95cea132143997a1870ae8dd1fc0db5c (patch) | |
tree | f199e3f4187091a7a7c78f7fd6901529658174f7 /lib/patches/fixtures_constraint_disabling.rb | |
parent | 59b5b15d56600ffc26d657dfea134ffcfc879725 (diff) | |
parent | a76010c99459559a29901ed75b847384248c7c6e (diff) |
Merge branch 'release/0.5' into develop
Diffstat (limited to 'lib/patches/fixtures_constraint_disabling.rb')
-rw-r--r-- | lib/patches/fixtures_constraint_disabling.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/patches/fixtures_constraint_disabling.rb b/lib/patches/fixtures_constraint_disabling.rb new file mode 100644 index 000000000..7d97e81f7 --- /dev/null +++ b/lib/patches/fixtures_constraint_disabling.rb @@ -0,0 +1,21 @@ +# An alternative way of disabling foreign keys in fixture loading in Postgres and +# does not require superuser permissions +# http://kopongo.com/2008/7/25/postgres-ri_constrainttrigger-error +require 'active_record/connection_adapters/postgresql_adapter' +module ActiveRecord + module ConnectionAdapters + class PostgreSQLAdapter < AbstractAdapter + def disable_referential_integrity(&block) + transaction { + begin + execute "SET CONSTRAINTS ALL DEFERRED" + yield + ensure + execute "SET CONSTRAINTS ALL IMMEDIATE" + end + } + end + end + end +end + |