OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/db/migrate/014_add_denormalized_costs_...

46 lines
1.6 KiB

class AddDenormalizedCostsFields < ActiveRecord::Migration
def self.up
add_column :time_entries, :overridden_costs, :decimal, :precision => 15, :scale => 2, :null => true
add_column :time_entries, :costs, :decimal, :precision => 15, :scale => 2, :null => true
add_column :time_entries, :rate_id, :integer
add_column :cost_entries, :costs, :decimal, :precision => 15, :scale => 2, :null => true
add_column :cost_entries, :rate_id, :integer
add_column :issues, :labor_costs, :decimal, :precision => 15, :scale => 2, :null => false, :default => 0.0
add_column :issues, :material_costs, :decimal, :precision => 15, :scale => 2, :null => false, :default => 0.0
add_column :issues, :overall_costs, :decimal, :precision => 15, :scale => 2, :null => false, :default => 0.0
# create a temporary admin user
u = User.new(:firstname => "Automatic", :lastname => "Migration")
u.admin = true
User.current = u
# update the new denormalized columns
transaction do
cache do
CostEntry.all.each {|e| e.update_costs!}
TimeEntry.all.each {|e| e.update_costs!}
Issue.all.each{|i| i.update_costs!}
end
end
# clean up after me
User.current = User.anonymous
end
def self.down
remove_column :time_entries, :overridden_costs
remove_column :time_entries, :costs
remove_column :time_entries, :rate_id
remove_column :cost_entries, :costs
remove_column :cost_entries, :rate_id
remove_column :issues, :labor_costs
remove_column :issues, :material_costs
end
end