Add fix for counter_cache migration to keep from throwing readonly column error.

unstable
Joe Vennix 2012-06-01 13:30:43 -05:00
parent ced5b9916e
commit 315d68b6f5
1 changed files with 6 additions and 5 deletions

View File

@ -1,14 +1,15 @@
class AddCounterCachesToHosts < ActiveRecord::Migration class AddCounterCachesToHosts < ActiveRecord::Migration
def self.up def self.up
add_column :hosts, :note_count, :integer, :default => 0 add_column :hosts, :note_count, :integer, :default => 0
add_column :hosts, :vuln_count, :integer, :default => 0 add_column :hosts, :vuln_count, :integer, :default => 0
add_column :hosts, :service_count, :integer, :default => 0 add_column :hosts, :service_count, :integer, :default => 0
Mdm::Host.reset_column_information Mdm::Host.reset_column_information
Mdm::Host.all.each do |h| Mdm::Host.all.each do |h|
h.update_attribute :note_count, h.notes.length Mdm::Host.reset_counters h.id, :notes
h.update_attribute :vuln_count, h.vulns.length Mdm::Host.reset_counters h.id, :vulns
h.update_attribute :service_count, h.services.length Mdm::Host.reset_counters h.id, :services
end end
end end
@ -17,4 +18,4 @@ class AddCounterCachesToHosts < ActiveRecord::Migration
remove_column :hosts, :vuln_count remove_column :hosts, :vuln_count
remove_column :hosts, :service_count remove_column :hosts, :service_count
end end
end end