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

Version Path
foreman_discovery-25.0.0 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-24.0.2 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-23.0.2 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-24.0.1 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-24.0.0 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-23.0.1 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-23.0.0 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-22.0.4 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-21.0.5 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-22.0.2 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-21.0.4 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-21.0.3 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-21.0.2 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-19.0.5 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-19.0.4 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-21.0.1 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-19.0.3 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-21.0.0 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-19.0.2 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb
foreman_discovery-20.0.1 db/migrate/20161006094714_add_constraints_on_subnets_smart_proxies.rb