Content
View differences
Updated by Kabiru Mwenja 11 months ago
## ADR: Extracting Journal#notes to Comments
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="https://community.openproject.org/api/v3/attachments/360549/content"></div></figure>
## Context <br>
**What ### Context
_What is the issue that is motivating this decision or change?**
change?_
See #62381 ###62381
Currently, work Work package activity comments are stored currently defined as `Journal#notes`. The `Journals` Journal#notes, Journals is a model is designed to capture that keeps track of data snapshots/changes for of any "Journable" object, providing a historical timeline of changes. For example, in data changeset timeline. E.g. In a `WorkPackage`, WorkPackage, it allows tracking attribute us to say track attributes changes such as "Assignee was changed from UserA to UserB".
However, there There are several nuances to this model that do are not align well with the intended behavior of necessarily relevant to a standalone "Comments" model:
* **Data Intensive:** Every 1. It is data intensive, every time a new journal is logged, logged a full data snapshot of the "Journable" (e.g., `WorkPackage`) e.g. "WorkPackage" is stored, regardless of whether the change stored.
2. There is comment-related.
* **Aggregation Complexity:** Journals support a configurable journal aggregation validity period, allowing changes within a certain time frame that allows "changes" to be merged aggregated into a single journal. one Journal if the change falls within the aggregation period
1. This aggregation introduces complexity, some complexity such as the need for virtual sequencing when rendering activities Activities, so that they are numbered sequentially (1..n).
* **Unnecessary Snapshots for Comments:** Each new 1..n
3. Every time a comment results in is added, a full new data snapshot, "Snapshot" is (unnecessarily) created, overriding the aggregation period if in the case that subsequent journals with notes (comments) are added. created
* **Complex Features:** Journals power 4. It powers complex, data and performance intensive features such as [baseline comparison](https://www.openproject.org/docs/user-guide/work-packages/baseline-comparison/), which are data and performance-intensive. the [Baseline Comparison](https://www.openproject.org/docs/user-guide/work-packages/baseline-comparison/)
* **Overloaded Concepts:** 5. The idea concept of "internal comments" is superimposed onto the `Journals` Journals table, even though it's is not relevant to all Journables.
* **Irrelevant Relations:** Relations 6. Comment relations such as `EmojiReaction` EmojiReaction and `Attachment` Attachment are also imposed on the Journal model, even when model albeit not relevant to all Journables need them.
<br>
📖 See the [Journals::CreateService](https://github.com/opf/openproject/blob/258af380b4401de54b917aeffa125e60e6b35ae7/app/services/journals/create_service.rb#L105-L196) for more details on the inner workings. workings
## ###
### Decision
**What _What is the change are we that we're proposing or making?** making?_
* Extract `Journal#notes` into a dedicated `Comments` model.
* Define Journal#notes to the Comments model, define an "Events" SQL view View that joins Journals and Comments into a unified, chronological timeline.
## Data Migration view
##### _Data Migration_
* Journals represent is one of the largest datasets in the system, so migrating dataset, and it's possible a data may migration would be time-intensive. Extensive time intensive- run adequate tests should be conducted during implementation. If necessary, implementation, consider performing the data migration via background jobs, though this adds complexity (see #65240).
## jobs if necessary albeit more complicated #65240
###
### Consequences
**What _What becomes easier or more difficult to do as a result of this change?** change?_
**Pros:**
* 1. Pro: **Separation of Concerns:** concerns**; It becomes easier to manage Comments can be managed as a standalone entity, reducing the risk of unintended entity without having to worry about Journal side-effects.
* 2. Pro: **Data Reduction:** A reduction**; a full Journable snapshot will is no longer be created for on every comment, comment write and comment aggregation is no longer overriden on comments creation will not override aggregation.
**Cons:**
* **Long-running
3. Con: **Long Running Data Migration:** Due to the size Migration;** Journals is one of the Journals largest dataset, and it's possible a data migration may take significant time. Adequate testing and possibly would be time intensive- run adequate tests during implementation, consider data migration via background jobs will be required. if necessary albeit more complicated.
* 4. Con: **Dynamic Sorting & Indexing (TBD):** Serving activities from an SQL view will require runtime sorting and possibly indexing for performance.
### Related topics
* **Authorization and Auditing:** Ensure Comments have clear ownership and audit trails, just (\*tbc)**; as Journals do.
* **Future-proofing:** Design the Comments model to Activities View will be extensible for features like rich-text support or threading.
* **API Consistency:** Update APIs served via an SQL view, we need to support the new Comments model, ensuring backward compatibility where needed.
* **Archival Strategy:** Plan for efficient archival sort and purging of legacy Journals once migration is complete.
* **Testing:** Develop comprehensive migration and regression tests to ensure data integrity and application stability throughout the transition. possibly index at runtime
<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="https://community.openproject.org/api/v3/attachments/360549/content"></div></figure>
## Context
**What
_What
Currently, work
However, there
* **Data Intensive:** Every
2. There
* **Aggregation Complexity:** Journals support a configurable
1.
* **Unnecessary Snapshots for Comments:** Each new
3. Every time a
* **Complex Features:** Journals power
* **Overloaded Concepts:**
* **Irrelevant Relations:** Relations
##
###
**What
* Extract `Journal#notes` into a dedicated `Comments` model.
* Define
## Data Migration
*
##
###
###
**What
**Pros:**
*
*
**Cons:**
* **Long-running
3. Con: **Long Running
*
### Related topics
* **Authorization and Auditing:** Ensure Comments have clear ownership and audit trails, just
* **Future-proofing:** Design the Comments model to
* **API Consistency:** Update APIs
* **Archival Strategy:** Plan for efficient archival
* **Testing:** Develop comprehensive migration and regression tests to ensure data integrity and application stability throughout the transition.