Sha256: f0d7d6a9f08e3180cc504e5aa3ad30f69eaac6d412ee0cb2ee3df82464f2f352
Contents?: true
Size: 959 Bytes
Versions: 56
Compression:
Stored size: 959 Bytes
Contents
class AddConstraintsOnSubnetsSmartProxies < ActiveRecord::Migration[4.2] def change # turn off Foreign Key checks if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' ActiveRecord::Migration.execute "SET CONSTRAINTS ALL DEFERRED;" elsif ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql' ActiveRecord::Migration.execute "SET FOREIGN_KEY_CHECKS=0;" end # if there's some wrong key already, clean the foreign key first Subnet.unscoped.where(["discovery_id IS NOT NULL AND discovery_id NOT IN (?)", SmartProxy.unscoped.pluck(:id)]).update_all(:discovery_id => nil) add_foreign_key "subnets", "smart_proxies", :name => "subnets_discovery_id_fk", :column => "discovery_id" # turn on Foreign Key checks in MySQL only if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql' ActiveRecord::Migration.execute "SET FOREIGN_KEY_CHECKS=1;" end end end
Version data entries
56 entries across 56 versions & 1 rubygems