Sha256: ca4bb9af0344b21558147484141be90f8331d62166a6b5cf966e7c1eb018bb4a

Contents?: true

Size: 832 Bytes

Versions: 43

Compression:

Stored size: 832 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!(: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

43 entries across 43 versions & 1 rubygems

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