-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14216 from opf/epic/40867-progress-reporting-for-…
…work-package-hierarchies [50953] Progress reporting for work package hierarchies: Change calculation and name of Work and Remaining work
- Loading branch information
Showing
27 changed files
with
1,625 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
db/migrate/20231227100753_fix_derived_work_and_remaining_work_values.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
class FixDerivedWorkAndRemainingWorkValues < ActiveRecord::Migration[7.0] | ||
def up | ||
execute(update_derived_values_as_sum_of_self_and_descendants_sql) | ||
end | ||
|
||
def down | ||
execute(update_derived_values_as_sum_of_descendants_sql) | ||
execute(update_leaf_derived_values_to_null_sql) | ||
end | ||
|
||
def update_derived_values_as_sum_of_self_and_descendants_sql | ||
<<~SQL.squish | ||
WITH wp_derived AS ( | ||
SELECT | ||
wph.ancestor_id AS id, | ||
sum(wp.estimated_hours) AS estimated_hours_sum, | ||
sum(wp.remaining_hours) AS remaining_hours_sum | ||
FROM work_package_hierarchies wph | ||
LEFT JOIN work_packages wp ON wph.descendant_id = wp.id | ||
GROUP BY wph.ancestor_id | ||
) | ||
UPDATE | ||
work_packages | ||
SET | ||
derived_estimated_hours = wp_derived.estimated_hours_sum, | ||
derived_remaining_hours = wp_derived.remaining_hours_sum | ||
FROM | ||
wp_derived | ||
WHERE work_packages.id = wp_derived.id | ||
SQL | ||
end | ||
|
||
def update_derived_values_as_sum_of_descendants_sql | ||
<<~SQL.squish | ||
WITH wp_derived AS ( | ||
SELECT | ||
wph.ancestor_id AS id, | ||
sum(wp.estimated_hours) AS estimated_hours_sum, | ||
sum(wp.remaining_hours) AS remaining_hours_sum | ||
FROM work_package_hierarchies wph | ||
LEFT JOIN work_packages wp ON wph.descendant_id = wp.id | ||
WHERE wph.ancestor_id != wph.descendant_id | ||
GROUP BY wph.ancestor_id | ||
) | ||
UPDATE | ||
work_packages | ||
SET | ||
derived_estimated_hours = wp_derived.estimated_hours_sum, | ||
derived_remaining_hours = wp_derived.remaining_hours_sum | ||
FROM | ||
wp_derived | ||
WHERE work_packages.id = wp_derived.id | ||
SQL | ||
end | ||
|
||
def update_leaf_derived_values_to_null_sql | ||
<<~SQL.squish | ||
UPDATE | ||
work_packages | ||
SET | ||
derived_estimated_hours = NULL, | ||
derived_remaining_hours = NULL | ||
WHERE | ||
id NOT IN ( | ||
SELECT ancestor_id | ||
FROM work_package_hierarchies | ||
WHERE generations > 0 | ||
) | ||
SQL | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.