OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[59539] Only set lag for the closest relation in the migration
Christophe Bliardafdf4308b5e3
diff --git a/app/workers/work_packages/automatic_mode/migrate_values_job.rb b/app/workers/work_packages/automatic_mode/migrate_values_job.rbindex c7b462e5e8c..39293396afe 100644--- a/app/workers/work_packages/automatic_mode/migrate_values_job.rb+++ b/app/workers/work_packages/automatic_mode/migrate_values_job.rb@@ -103,6 +103,7 @@ class WorkPackages::AutomaticMode::MigrateValuesJob < ApplicationJob# Here is the algorithm:# - Take all follows relations with dates+ # - Filter to keep only the closest relation for a same successor# - Generate a series of dates between the min date and the max date and# filter for working days# - Use both information to count the number of working days between@@ -111,6 +112,7 @@ class WorkPackages::AutomaticMode::MigrateValuesJob < ApplicationJobWITH follows_relations_with_dates AS (SELECTrelations.id as id,+ relations.from_id as succ_id,COALESCE(wp_pred.due_date, wp_pred.start_date) as pred_date,COALESCE(wp_succ.start_date, wp_succ.due_date) as succ_dateFROM relations@@ -120,6 +122,14 @@ class WorkPackages::AutomaticMode::MigrateValuesJob < ApplicationJobAND COALESCE(wp_pred.due_date, wp_pred.start_date) IS NOT NULLAND COALESCE(wp_succ.start_date, wp_succ.due_date) IS NOT NULL),+ closest_follows_relations_with_dates AS (+ SELECT DISTINCT ON (succ_id)+ id,+ pred_date,+ succ_date+ FROM follows_relations_with_dates+ ORDER BY succ_id, pred_date DESC+ ),working_dates AS (SELECT date::dateFROM generate_series(@@ -137,8 +147,8 @@ class WorkPackages::AutomaticMode::MigrateValuesJob < ApplicationJobWHERE date > pred_dateAND date < succ_date)- FROM follows_relations_with_dates- WHERE relations.id = follows_relations_with_dates.id+ FROM closest_follows_relations_with_dates+ WHERE relations.id = closest_follows_relations_with_dates.idSQLenddiff --git a/spec/migrations/update_scheduling_mode_and_lags_spec.rb b/spec/migrations/update_scheduling_mode_and_lags_spec.rbindex 81ca3996018..0dcf3ae5209 100644--- a/spec/migrations/update_scheduling_mode_and_lags_spec.rb+++ b/spec/migrations/update_scheduling_mode_and_lags_spec.rb@@ -222,4 +222,21 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model doexpect(relations.map(&:lag)).to eq([0, 0, 2])endend++ context "for a work package following multiple work packages" do+ shared_let_work_packages(<<~TABLE)+ subject | MTWTFSS | properties+ predecessor 1 | XX |+ predecessor 2 | XX |+ predecessor 3 | X |+ follower | XX | follows predecessor 1, follows predecessor 2, follows predecessor 3+ TABLE++ it "sets a lag only to the closest relation" do+ run_migration++ relations = _table.relations.map(&:reload)+ expect(relations.map(&:lag)).to eq([0, 2, 0])+ end+ endend