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