1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-06 07:31:31 +00:00
redmine/db/migrate/20150525103953_clear_estimated_hours_on_parent_issues.rb
Go MAEDA 5861160ffc Add "frozen_string_literal: false" for all files (#26561).
This will be changed to true in the future.


git-svn-id: http://svn.redmine.org/redmine/trunk@17947 e93f8b46-1217-0410-a6f0-8f06a7374b81
2019-03-15 01:32:57 +00:00

18 lines
685 B
Ruby

# frozen_string_literal: false
class ClearEstimatedHoursOnParentIssues < ActiveRecord::Migration[4.2]
def self.up
# Clears estimated hours on parent issues
Issue.where("rgt > lft + 1 AND estimated_hours > 0").update_all :estimated_hours => nil
end
def self.down
table_name = Issue.table_name
leaves_sum_select = "SELECT SUM(leaves.estimated_hours) FROM (SELECT * FROM #{table_name}) AS leaves" +
" WHERE leaves.root_id = #{table_name}.root_id AND leaves.lft > #{table_name}.lft AND leaves.rgt < #{table_name}.rgt" +
" AND leaves.rgt = leaves.lft + 1"
Issue.where("rgt > lft + 1").update_all "estimated_hours = (#{leaves_sum_select})"
end
end