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
rework life cycle data structure
ulfertsf494c9d50776
diff --git a/db/migrate/20250324161229_merge_lifecycle_steps.rb b/db/migrate/20250324161229_merge_lifecycle_steps.rbnew file mode 100644index 00000000000..9de77b5c68e--- /dev/null+++ b/db/migrate/20250324161229_merge_lifecycle_steps.rb@@ -0,0 +1,98 @@+# frozen_string_literal: true++#+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class MergeLifecycleSteps < ActiveRecord::Migration[8.0]+ def change+ reversible do |direction|+ direction.up do+ delete_life_cycle_project_queries+ delete_life_cycles+ end+ end++ change_table(:project_life_cycle_step_definitions, bulk: true) do |t|+ t.column :start_gate, :boolean, default: false, null: false+ t.column :start_gate_name, :string+ # TODO: Consider renaming all 'end_date' columns to 'finish_date' to be in line with how the+ # dates are to be named for work packages+ t.column :end_gate, :boolean, default: false, null: false+ t.column :end_gate_name, :string++ t.remove :type, type: :string+ end++ change_table(:project_life_cycle_steps) do |t|+ t.remove :type, type: :string+ end+ end++ def delete_life_cycles+ # The feature is behind a feature flag and not yet released.+ # Potential data is thus simply removed and the seeder will add the updated data.+ execute <<-SQL.squish+ DELETE FROM project_life_cycle_steps;+ SQL++ execute <<-SQL.squish+ DELETE FROM project_life_cycle_step_definitions;+ SQL++ execute <<-SQL.squish+ DELETE FROM project_life_cycle_step_journals;+ SQL+ end++ def delete_life_cycle_project_queries+ step_ids = select_all(<<-SQL.squish).to_a.flatten.flat_map(&:values)+ SELECT id from project_life_cycle_step_definitions;+ SQL++ if step_ids.any?+ # This should be possible to be done like with orders and filters+ execute <<-SQL.squish+ DELETE+ FROM project_queries+ WHERE selects::jsonb ?| array[#{step_ids.map { |id| "'lcsd_#{id}'" }.join(',')}];+ SQL+ end++ execute <<-SQL.squish+ DELETE+ FROM project_queries+ WHERE jsonb_path_exists(orders::jsonb, '$[*] ? (@.attribute like_regex "^lcsd.*")');+ SQL++ execute <<-SQL.squish+ DELETE+ FROM project_queries+ WHERE jsonb_path_exists(filters::jsonb, '$[*] ? (@.attribute like_regex "^lcsd.*")');+ SQL+ end+enddiff --git a/spec/migrations/merge_lifecycle_steps_spec.rb b/spec/migrations/merge_lifecycle_steps_spec.rbnew file mode 100644index 00000000000..98bce19e71c--- /dev/null+++ b/spec/migrations/merge_lifecycle_steps_spec.rb@@ -0,0 +1,140 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# ++++require "spec_helper"+require Rails.root.join("db/migrate/20250324161229_merge_lifecycle_steps.rb")++RSpec.describe MergeLifecycleSteps, type: :model do+ shared_let(:colors) { create_list(:color, 3) }+ shared_let(:project) { create(:project) }+ shared_let(:project_journal) { project.journals.first }++ before do+ ActiveRecord::Migration.suppress_messages do+ described_class.new.migrate(:down)+ end++ ActiveRecord::Base.connection.execute(+ <<-SQL.squish+ INSERT INTO project_life_cycle_step_definitions (id, type, name, position, color_id, created_at, updated_at)+ VALUES+ (1, 'Project::StageDefinition', 'Initiating', 1, #{colors.first.id}, NOW(), NOW()),+ (2, 'Project::GateDefinition', 'Ready for Executing', 2, #{colors.second.id}, NOW(), NOW()),+ (3, 'Project::StageDefinition', 'Executing', 3, #{colors.third.id}, NOW(), NOW())+ SQL+ )++ ActiveRecord::Base.connection.execute(+ <<-SQL.squish+ INSERT INTO project_life_cycle_steps (id, type, start_date, end_date, active, project_id, definition_id, created_at, updated_at)+ VALUES+ (1, 'Project::Stage', '#{Time.zone.today}', '#{Time.zone.today + 5.days}', true, #{project.id}, 1, NOW(), NOW()),+ (2, 'Project::Gate', '#{Time.zone.today + 5.days}', '#{Time.zone.today + 5.days}', true, #{project.id}, 2, NOW(), NOW()),+ (3, 'Project::Stage', '#{Time.zone.today + 6.days}', '#{Time.zone.today + 15.days}', false, #{project.id}, 3, NOW(), NOW())+ SQL+ )++ ActiveRecord::Base.connection.execute(+ <<-SQL.squish+ INSERT INTO project_life_cycle_step_journals (journal_id, life_cycle_step_id, start_date, end_date, active)+ VALUES+ (#{project_journal.id}, 1, '#{Time.zone.today}', '#{Time.zone.today + 5.days}', true),+ (#{project_journal.id}, 2, '#{Time.zone.today + 5.days}', '#{Time.zone.today + 5.days}', true),+ (#{project_journal.id}, 3, '#{Time.zone.today + 6.days}', '#{Time.zone.today + 15.days}', false)+ SQL+ )++ # Need to be after the life cycle steps are created+ query_without_lifecycle+ query_with_lifecycle_any_filter+ query_with_lifecycle_order+ query_with_lifecycle_select+ query_with_lifecycle_gate_filter+ query_with_lifecycle_stage_filter+ end++ let(:query_without_lifecycle) { create(:project_query) }+ let(:query_with_lifecycle_select) { create(:project_query, select: %w[name lcsd_2 project_status]) }+ let(:query_with_lifecycle_order) do+ create(:project_query).tap do |q|+ q.order("lcsd_3" => "desc")+ q.save(validate: false)+ end+ end+ let(:query_with_lifecycle_any_filter) do+ create(:project_query).tap do |q|+ q.where("lcsd_any", "t", [])+ q.save+ end+ end+ let(:query_with_lifecycle_gate_filter) do+ create(:project_query).tap do |q|+ q.where("lcsd_gate_2", "t", [])+ q.save+ end+ end+ let(:query_with_lifecycle_stage_filter) do+ create(:project_query).tap do |q|+ q.where("lcsd_stage_1", "t", [])+ q.save+ end+ end++ subject { ActiveRecord::Migration.suppress_messages { described_class.new.migrate(:up) } }++ it "removes all project life cycle steps" do+ expect { subject }+ .to change { ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_life_cycle_steps")["count"] }+ .from(3).to(0)+ end++ it "removes all project life cycle step definitions" do+ expect { subject }+ .to change { ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_life_cycle_step_definitions")["count"] }+ .from(3).to(0)+ end++ it "removes all project life cycle step journal entries but leaves the journal" do+ expect { subject }+ .to(change { ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_life_cycle_step_journals")["count"] }+ .from(3).to(0)+ .and(change do+ ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM journals where id =#{project_journal.id}")["count"]+ end.by(0)))+ end++ it "removes all queries with life cycle references in order, select or filters" do+ expect { subject }+ .to(change(ProjectQuery, :count).from(6).to(1))++ expect(ProjectQuery)+ .to exist(id: query_without_lifecycle.id)+ end+end