diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-24 06:44:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 06:44:06 +0900 |
commit | d147ed02a00fe50f3428962dfadb5de076c56a5e (patch) | |
tree | 3fb66c04ff059b8537b51d47eb25bd049eddf618 /activerecord | |
parent | ec7bf399b12c8aea6d506106cc5408f2f17ed349 (diff) | |
parent | 1015cab6e4db5f18deadba0a6eb2adbe82ffe585 (diff) | |
download | rails-d147ed02a00fe50f3428962dfadb5de076c56a5e.tar.gz rails-d147ed02a00fe50f3428962dfadb5de076c56a5e.tar.bz2 rails-d147ed02a00fe50f3428962dfadb5de076c56a5e.zip |
Merge pull request #30964 from yahonda/remove_supports_disable_referential_integrity
Remove `supports_disable_referential_integrity?`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb b/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb index 386d22a9bd..8df91c988b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb @@ -4,26 +4,21 @@ module ActiveRecord module ConnectionAdapters module PostgreSQL module ReferentialIntegrity # :nodoc: - def supports_disable_referential_integrity? # :nodoc: - true - end - def disable_referential_integrity # :nodoc: - if supports_disable_referential_integrity? - original_exception = nil + 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 + 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 + 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. @@ -32,17 +27,14 @@ Rails needs superuser privileges to disable referential integrity. cause: #{original_exception.try(:message)} WARNING - raise e - end + 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 + begin + transaction(requires_new: true) do + execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";")) end - else - yield + rescue ActiveRecord::ActiveRecordError end end end |