Sha256: f398f1da95c1c7e0350faaa23be3479bd889e37dcceb03590106270cde7dc12f

Contents?: true

Size: 1.21 KB

Versions: 22

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

22 entries across 22 versions & 1 rubygems

Version Path
activerecord-6.0.6.1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.6 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.5.1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.5 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.8 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.7 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.6 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.5 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.4 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.3 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.2 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4.1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.4 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.7 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.6 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.5 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.4 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.3 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.2 lib/active_record/connection_adapters/postgresql/referential_integrity.rb
activerecord-6.0.3.1 lib/active_record/connection_adapters/postgresql/referential_integrity.rb