Skip to content

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

rename lifecycle tables

ulfertsb0b762469945
diff --git a/app/services/journals/create_service/project_life_cycle_step.rb b/app/services/journals/create_service/project_life_cycle_step.rb
index 78be34753af..dcc76976976 100644
--- a/app/services/journals/create_service/project_life_cycle_step.rb
+++ b/app/services/journals/create_service/project_life_cycle_step.rb
@@ -31,12 +31,12 @@
class Journals::CreateService
class ProjectLifeCycleStep < Association
def associated?
- journable.respond_to?(:life_cycle_steps)
+ journable.respond_to?(:phases)
end
def cleanup_predecessor(predecessor)
cleanup_predecessor_for(predecessor,
- "project_life_cycle_step_journals",
+ "project_phase_journals",
:journal_id,
:id)
end
@@ -44,23 +44,23 @@ class Journals::CreateService
def insert_sql
sanitize(<<~SQL.squish, journable_id:)
INSERT INTO
- project_life_cycle_step_journals (
+ project_phase_journals (
journal_id,
- life_cycle_step_id,
+ phase_id,
start_date,
end_date,
active
)
SELECT
#{id_from_inserted_journal_sql},
- project_life_cycle_steps.id,
- project_life_cycle_steps.start_date,
- project_life_cycle_steps.end_date,
- project_life_cycle_steps.active
- FROM project_life_cycle_steps
+ project_phases.id,
+ project_phases.start_date,
+ project_phases.end_date,
+ project_phases.active
+ FROM project_phases
WHERE
#{only_if_created_sql}
- AND project_life_cycle_steps.project_id = :journable_id
+ AND project_phases.project_id = :journable_id
SQL
end
@@ -71,19 +71,19 @@ class Journals::CreateService
FROM
max_journals
LEFT OUTER JOIN
- project_life_cycle_step_journals
+ project_phase_journals
ON
- project_life_cycle_step_journals.journal_id = max_journals.id
+ project_phase_journals.journal_id = max_journals.id
FULL JOIN
(SELECT *
- FROM project_life_cycle_steps
- WHERE project_life_cycle_steps.project_id = :journable_id) life_cycle_steps
+ FROM project_phases
+ WHERE project_phases.project_id = :journable_id) phases
ON
- life_cycle_steps.id = project_life_cycle_step_journals.life_cycle_step_id
+ phases.id = project_phase_journals.life_cycle_step_id
WHERE
- life_cycle_steps.start_date IS DISTINCT FROM project_life_cycle_step_journals.start_date
- OR life_cycle_steps.end_date IS DISTINCT FROM project_life_cycle_step_journals.end_date
- OR life_cycle_steps.active IS DISTINCT FROM project_life_cycle_step_journals.active
+ phases.start_date IS DISTINCT FROM project_phase_journals.start_date
+ OR phases.end_date IS DISTINCT FROM project_phase_journals.end_date
+ OR phases.active IS DISTINCT FROM project_phase_journals.active
SQL
end
end
diff --git a/db/migrate/20250324161229_merge_lifecycle_steps.rb b/db/migrate/20250324161229_merge_lifecycle_steps.rb
index 9de77b5c68e..6d983303fa3 100644
--- a/db/migrate/20250324161229_merge_lifecycle_steps.rb
+++ b/db/migrate/20250324161229_merge_lifecycle_steps.rb
@@ -37,20 +37,8 @@ class MergeLifecycleSteps < ActiveRecord::Migration[8.0]
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
+ adapt_tables
+ rename_tables
end
def delete_life_cycles
@@ -95,4 +83,31 @@ class MergeLifecycleSteps < ActiveRecord::Migration[8.0]
WHERE jsonb_path_exists(filters::jsonb, '$[*] ? (@.attribute like_regex "^lcsd.*")');
SQL
end
+
+ def adapt_tables
+ 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
+
+ change_table(:project_life_cycle_step_journals) do |t|
+ t.rename :life_cycle_step_id, :phase_id
+ end
+ end
+
+ def rename_tables
+ rename_table :project_life_cycle_step_definitions, :project_phase_definitions
+ rename_table :project_life_cycle_steps, :project_phases
+ rename_table :project_life_cycle_step_journals, :project_phase_journals
+ end
end
diff --git a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
index 39a3f55fe09..97223846139 100644
--- a/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_changes.rb
@@ -100,8 +100,8 @@ module JournalChanges
::Acts::Journalized::Differ::Association.new(
predecessor,
self,
- association: :project_life_cycle_step_journals,
- id_attribute: :life_cycle_step_id
+ association: :project_phase_journals,
+ id_attribute: :phase_id
).multiple_attributes_changes(
%i[active date_range],
key_prefix: "project_life_cycle_step"
diff --git a/spec/migrations/merge_lifecycle_steps_spec.rb b/spec/migrations/merge_lifecycle_steps_spec.rb
index 98bce19e71c..fe3775c0963 100644
--- a/spec/migrations/merge_lifecycle_steps_spec.rb
+++ b/spec/migrations/merge_lifecycle_steps_spec.rb
@@ -109,25 +109,42 @@ RSpec.describe MergeLifecycleSteps, type: :model do
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)
+ it "removes all project life cycle steps and renames the table" do
+ expect(ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_life_cycle_steps")["count"])
+ .to eq 3
+
+ subject
+
+ expect(ActiveRecord::Base.connection.table_exists?("project_life_cycle_steps"))
+ .to be false
+ expect(ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_phases")["count"])
+ .to eq 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)
+ it "removes all project life cycle step definitions and renames the table" do
+ expect(ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_life_cycle_step_definitions")["count"])
+ .to eq 3
+
+ subject
+
+ expect(ActiveRecord::Base.connection.table_exists?("project_life_cycle_step_definitions"))
+ .to be false
+ expect(ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_phase_definitions")["count"])
+ .to eq 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)))
+ it "removes all project life cycle step journal entries but leaves the journal - the step journal table is removed" do
+ expect(ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_life_cycle_step_journals")["count"])
+ .to eq 3
+
+ subject
+
+ expect(ActiveRecord::Base.connection.table_exists?("project_life_cycle_step_journals"))
+ .to be false
+ expect(ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM project_phase_journals")["count"])
+ .to eq 0
+ expect(Journal)
+ .to exist(id: project_journal.id)
end
it "removes all queries with life cycle references in order, select or filters" do