Sha256: 22041b7850d7176d9ff96ddbc3ba7c062a0abe393b8b0cde3b44cd8c897ed465
Contents?: true
Size: 954 Bytes
Versions: 1
Compression:
Stored size: 954 Bytes
Contents
class AddConstraintsOnSubnetsSmartProxies < ActiveRecord::Migration 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foreman_discovery-9.1.5 | db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb |