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] Migration: followers and parents have automatic scheduling mode
Christophe Bliarddcaf5aa892dc
diff --git a/app/workers/work_packages/automatic_mode/migrate_values_job.rb b/app/workers/work_packages/automatic_mode/migrate_values_job.rbindex 88765340935..80e732487af 100644--- a/app/workers/work_packages/automatic_mode/migrate_values_job.rb+++ b/app/workers/work_packages/automatic_mode/migrate_values_job.rb@@ -29,7 +29,9 @@class WorkPackages::AutomaticMode::MigrateValuesJob < ApplicationJobdef performwith_temporary_table do- change_scheduling_mode_to_manual_mode+ change_scheduling_mode_to_manual+ change_scheduling_mode_to_automatic_for_followers+ change_scheduling_mode_to_automatic_for_parentscopy_values_to_work_packages_and_update_journalsendend@@ -63,13 +65,38 @@ class WorkPackages::AutomaticMode::MigrateValuesJob < ApplicationJobSQLend- def change_scheduling_mode_to_manual_mode+ def change_scheduling_mode_to_manualexecute(<<~SQL.squish)UPDATE temp_wp_valuesSET schedule_manually = trueSQLend+ def change_scheduling_mode_to_automatic_for_followers+ execute(<<~SQL.squish)+ UPDATE temp_wp_values+ SET schedule_manually = false+ WHERE EXISTS (+ SELECT 1+ FROM relations+ WHERE relations.from_id = temp_wp_values.id+ AND relations.relation_type = 'follows'+ )+ SQL+ end++ def change_scheduling_mode_to_automatic_for_parents+ execute(<<~SQL.squish)+ UPDATE temp_wp_values+ SET schedule_manually = false+ WHERE id IN (+ SELECT DISTINCT parent_id+ FROM work_packages+ WHERE parent_id IS NOT NULL+ )+ SQL+ end+def copy_values_to_work_packages_and_update_journalsupdated_work_package_ids = copy_values_to_work_packagescreate_journals_for_updated_work_packages(updated_work_package_ids)diff --git a/spec/migrations/update_scheduling_mode_and_lags_spec.rb b/spec/migrations/update_scheduling_mode_and_lags_spec.rbindex 266b5fbef31..0f58a4e0a16 100644--- a/spec/migrations/update_scheduling_mode_and_lags_spec.rb+++ b/spec/migrations/update_scheduling_mode_and_lags_spec.rb@@ -35,6 +35,7 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model doperform_enqueued_jobs doActiveRecord::Migration.suppress_messages { described_class.new.up }end+ table_work_packages.map(&:reload) if defined?(table_work_packages)endshared_let(:author) { create(:user) }@@ -58,11 +59,13 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model dowp automatic | automaticTABLE- before do+ it "creates a journal entry only for the changed work packages" do+ expect(wp_already_manual.journals.count).to eq(1)+ expect(wp_automatic.journals.count).to eq(1)+ expect(wp_automatic.lock_version).to eq(0)+run_migration- end- it "creates a journal entry only for the changed work packages" doexpect(wp_already_manual.journals.count).to eq(1)expect(wp_automatic.journals.count).to eq(2)@@ -76,9 +79,7 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model doendaggregate_failures "the lock_version of the work package is incremented" do- previous_lock_version = wp_automatic.lock_version- wp_automatic.reload- expect(wp_automatic.lock_version).to be > previous_lock_version+ expect(wp_automatic.lock_version).to be > 0endaggregate_failures "changes the updated_at of the work package" do@@ -110,8 +111,47 @@ RSpec.describe UpdateSchedulingModeAndLags, type: :model doit "switches to manual scheduling" dorun_migration- table_work_packages.map(&:reload)expect(table_work_packages).to all(be_schedule_manually)endend++ # spec from #42388, "Migration from an earlier version" section+ context "for work packages following another one" do+ let_work_packages(<<~TABLE)+ subject | start date | due date | scheduling mode | properties+ main | 2024-11-19 | 2024-11-19 | manual |+ wp automatic 1 | 2024-11-20 | 2024-11-21 | automatic | follows main+ wp automatic 2 | | 2024-11-21 | automatic | follows main+ wp automatic 3 | 2024-11-20 | | automatic | follows main+ wp automatic 4 | | | automatic | follows main+ wp manual 1 | 2024-11-20 | 2024-11-21 | manual | follows main+ wp manual 2 | | 2024-11-21 | manual | follows main+ wp manual 3 | 2024-11-20 | | manual | follows main+ wp manual 4 | | | manual | follows main+ TABLE++ # TODO: should work packages without any dates really be switched to manual like the specs say?+ it "switches to automatic scheduling" do+ run_migration++ expect(main).to be_schedule_manually+ expect(table_work_packages - [main]).to all(be_schedule_automatically)+ end+ end++ # spec from #42388, "Migration from an earlier version" section+ context "for parent work packages" do+ let_work_packages(<<~TABLE)+ hierarchy | scheduling mode |+ parent | manual |+ child | manual |+ TABLE++ it "switches to automatic scheduling" do+ run_migration++ expect(parent).to be_schedule_automatically+ expect(child).to be_schedule_manually+ end+ endend