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
Add a cause JSONB field for Journals
Klaus Zanders51bef513fc00
diff --git a/app/models/journal.rb b/app/models/journal.rbindex 9fc5fcbffd5..cc4aa27a4b5 100644--- a/app/models/journal.rb+++ b/app/models/journal.rb@@ -49,8 +49,15 @@ class Journal < ApplicationRecordregister_journal_formatter :wiki_diff, OpenProject::JournalFormatter::WikiDiffregister_journal_formatter :time_entry_named_association, OpenProject::JournalFormatter::TimeEntryNamedAssociation+ # Attributes related to the cause are stored in a JSONB column so we can easily add new relations and related+ # attributes without a heavy database migration. Fields will be prefixed with `cause_` but are stored in the JSONB+ # hash without that prefix+ store_accessor :cause, %i[type work_package_id], prefix: true+ VALID_CAUSE_TYPES = %w[work_package_predecessor_changed_times work_package_successor_changed_times].freeze+# Make sure each journaled model instance only has unique version idsvalidates :version, uniqueness: { scope: %i[journable_id journable_type] }+ validates :cause_type, inclusion: { in: VALID_CAUSE_TYPES, allow_blank: true }belongs_to :userbelongs_to :journable, polymorphic: true@@ -127,6 +134,10 @@ class Journal < ApplicationRecord(!notes || notes&.empty?) && get_changes.empty?end+ def has_cause?+ cause_type.present?+ end+privatedef predecessordiff --git a/db/migrate/20230606083221_add_cause_to_journal.rb b/db/migrate/20230606083221_add_cause_to_journal.rbnew file mode 100644index 00000000000..43d0603b6f0--- /dev/null+++ b/db/migrate/20230606083221_add_cause_to_journal.rb@@ -0,0 +1,5 @@+class AddCauseToJournal < ActiveRecord::Migration[7.0]+ def change+ add_column :journals, :cause, :jsonb, default: {}+ end+end