Fixed issue #1261 - Adding foreign keys for inconsistent PG tables breaks update.

This commit is contained in:
Thorsten Eckel 2017-08-10 11:20:29 +02:00
parent 577c8b7995
commit 5f17ceb48a

View file

@ -1,4 +1,6 @@
class ForeignKeys < ActiveRecord::Migration
disable_ddl_transaction!
def change
# return if it's a new setup
@ -217,10 +219,12 @@ class ForeignKeys < ActiveRecord::Migration
]
foreign_keys.each do |foreign_key|
begin
ActiveRecord::Migration.add_foreign_key(*foreign_key)
rescue => e
Rails.logger.error "Inconsistent data status detected while adding foreign key '#{foreign_key.inspect}': #{e.message}"
ActiveRecord::Base.transaction do
begin
add_foreign_key(*foreign_key)
rescue => e
Rails.logger.error "Inconsistent data status detected while adding foreign key '#{foreign_key.inspect}': #{e.message}"
end
end
end
end