diff --git a/data/sql/migrate/20120601152442_add_counter_caches_to_hosts.rb b/data/sql/migrate/20120601152442_add_counter_caches_to_hosts.rb index fb0a64c3a1..fcd2f9e0ca 100644 --- a/data/sql/migrate/20120601152442_add_counter_caches_to_hosts.rb +++ b/data/sql/migrate/20120601152442_add_counter_caches_to_hosts.rb @@ -1,14 +1,15 @@ class AddCounterCachesToHosts < ActiveRecord::Migration + def self.up add_column :hosts, :note_count, :integer, :default => 0 add_column :hosts, :vuln_count, :integer, :default => 0 add_column :hosts, :service_count, :integer, :default => 0 - + Mdm::Host.reset_column_information Mdm::Host.all.each do |h| - h.update_attribute :note_count, h.notes.length - h.update_attribute :vuln_count, h.vulns.length - h.update_attribute :service_count, h.services.length + Mdm::Host.reset_counters h.id, :notes + Mdm::Host.reset_counters h.id, :vulns + Mdm::Host.reset_counters h.id, :services end end @@ -17,4 +18,4 @@ class AddCounterCachesToHosts < ActiveRecord::Migration remove_column :hosts, :vuln_count remove_column :hosts, :service_count end -end +end \ No newline at end of file