Sha256: 6d2e27552abe59b3aa30a54994965e4eb04b9bee9333ba87bbccb70aae6de631

Contents?: true

Size: 1.21 KB

Versions: 50

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      module ReferentialIntegrity # :nodoc:
        def disable_referential_integrity # :nodoc:
          original_exception = nil

          begin
            transaction(requires_new: true) do
              execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
            end
          rescue ActiveRecord::ActiveRecordError => e
            original_exception = e
          end

          begin
            yield
          rescue ActiveRecord::InvalidForeignKey => e
            warn <<-WARNING
WARNING: Rails was not able to disable referential integrity.

This is most likely caused due to missing permissions.
Rails needs superuser privileges to disable referential integrity.

    cause: #{original_exception.try(:message)}

              WARNING
            raise e
          end

          begin
            transaction(requires_new: true) do
              execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
            end
          rescue ActiveRecord::ActiveRecordError
          end
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 6 rubygems

Version Path
activerecord-6.0.2.rc2 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-5.2.4 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.2.rc1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-5.2.4.rc1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.1.rc1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.0 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
spiral_form-0.1.1 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
spiral_form-0.1.0 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.0.rc2 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.0.rc1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-5.2.3 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-5.2.3.rc1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.0.beta3 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-5.2.2.1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.0.beta2 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.0.beta1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
nullifyable-0.1.0 vendor/bundle/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql/referential_integrity.rb