Sha256: bdfeaec81ccb4fb5f843bfc1defd3a7ea233bd9a6c7720c62b13a755c34518ac

Contents?: true

Size: 1.21 KB

Versions: 30

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module CipherStashPG
      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&.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

30 entries across 30 versions & 1 rubygems

Version Path
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.8.1 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.8.0 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.19 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.18 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.17 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.16 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.15 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.14 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.12 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.11 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.10 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.9 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.8 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.7 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.6 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
activerecord-cipherstash-pg-adapter-0.7.5 lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb