Sha256: 89eee68efe6891bc39674c43602a6aebc735fd8725cebb508b28243447c572d3

Contents?: true

Size: 843 Bytes

Versions: 12

Compression:

Stored size: 843 Bytes

Contents

 class AddPriorityScoreToDiscoveryRules < ActiveRecord::Migration[4.2]
  class DiscoveryRules < ActiveRecord::Base
  end

  def up
    # to make enough room to future entries. set initial score and delta to 100
    delta = score = 100
    # This loop keeps the same priority behavior before migration
    # and makes sure there are no two entities with the same priority.
    DiscoveryRules.reset_column_information
    DiscoveryRules.unscoped.reorder(:priority, :created_at).find_each do |rule|
      rule.update_attributes!(:priority => score)
      score += delta
    end
    change_column :discovery_rules, :priority, :integer, null: false
    add_index :discovery_rules, :priority, unique: true
  end

  def down
    remove_index :discovery_rules, :priority
    change_column :discovery_rules, :priority, :integer, default: 0
  end

 end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman_discovery-16.0.1 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-16.0.0 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-15.1.0 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-15.0.2 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-15.0.1 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-15.0.0 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-14.0.1 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-14.0.0 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-13.0.1 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-12.0.2 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-12.0.1 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb
foreman_discovery-12.0.0 db/migrate/20180412124505_add_priority_score_to_discovery_rules.rb