Sha256: 18a1e3bbfb3a3b34ecd33884fee58428e4fb29d0dd2110bfe5e74945d2ee112a

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# Hack to disable_referential_integrity for postgres users with sane
# permissions, uses deferral of constraints instead of disablement of the
# superuser-owned per-table triggers. Allows testing with fixtures which
# otherwise produce RI_ConstraintTrigger Errors.
#
# source: http://kopongo.com/2008/7/25/postgres-ri_constrainttrigger-error
# ref: https://github.com/matthuhiggins/foreigner/issues/61
class ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter < ::ActiveRecord::ConnectionAdapters::AbstractAdapter

  alias_method :supports_deferring_all_constraints?, :supports_disable_referential_integrity?
  def defer_all_constraints(&block)
    return unless supports_deferring_all_constraints?

    transaction do
      begin
        execute "SET CONSTRAINTS ALL DEFERRED"
        yield
      ensure
        execute "SET CONSTRAINTS ALL IMMEDIATE"
      end
    end
  end
  alias_method :disable_triggers_on_each_table, :disable_referential_integrity
  alias_method :disable_referential_integrity, :defer_all_constraints

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails3_pg_deferred_constraints-0.0.1 lib/rails3_pg_deferred_constraints/postgresql_adapter.rb