Sha256: cc0c826b51022dcc1eadff2315a8189119f6ce37ec22b377b5b8cabce3f0a9dd

Contents?: true

Size: 703 Bytes

Versions: 22

Compression:

Stored size: 703 Bytes

Contents

class AddCredsCounterCache < ActiveRecord::Migration[4.2]
  def up
    add_column :hosts, :cred_count, :integer, :default => 0
    Mdm::Host.reset_column_information
    # Set initial counts
    cred_service_ids = Set.new
    Mdm::Cred.all.each {|c| cred_service_ids << c.service_id}
    cred_service_ids.each do |service_id|
      #Mdm::Host.reset_counters(Mdm::Service.find(service_id).host.id, :creds)
      begin
        host = Mdm::Service.find(service_id).host
      rescue
        next
      end
      next if host.nil? # This can happen with orphan creds/services
      host.cred_count = host.creds.count
      host.save
    end
  end

  def down
    remove_column :hosts, :cred_count
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
wg-metasploit_data_models-4.1.4.02 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-6.0.5 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-6.0.4 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-6.0.3 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-6.0.2 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-6.0.1 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-6.0.0 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.6 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.5 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.4 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.3 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.2 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.1 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-5.0.0 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-4.1.4 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-4.1.3 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-4.1.2 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-4.1.1 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-4.1.0 db/migrate/20130423211152_add_creds_counter_cache.rb
metasploit_data_models-4.0.2 db/migrate/20130423211152_add_creds_counter_cache.rb