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.

20150525103953_clear_estimated_hours_on_parent_issues.rb 653B

123456789101112131415
  1. class ClearEstimatedHoursOnParentIssues < ActiveRecord::Migration[4.2]
  2. def self.up
  3. # Clears estimated hours on parent issues
  4. Issue.where("rgt > lft + 1 AND estimated_hours > 0").update_all :estimated_hours => nil
  5. end
  6. def self.down
  7. table_name = Issue.table_name
  8. leaves_sum_select = "SELECT SUM(leaves.estimated_hours) FROM (SELECT * FROM #{table_name}) AS leaves" +
  9. " WHERE leaves.root_id = #{table_name}.root_id AND leaves.lft > #{table_name}.lft AND leaves.rgt < #{table_name}.rgt" +
  10. " AND leaves.rgt = leaves.lft + 1"
  11. Issue.where("rgt > lft + 1").update_all "estimated_hours = (#{leaves_sum_select})"
  12. end
  13. end