Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Django imports
from django.core.management.base import BaseCommand
from django.db import transaction

# Module imports
from plane.db.models import Description
from plane.db.models import IssueComment


class Command(BaseCommand):
help = "Create Description records for existing IssueComment"

def handle(self, *args, **kwargs):
batch_size = 500

while True:
comments = list(
IssueComment.objects.filter(deleted_at__isnull=True, description_id__isnull=True)[:batch_size]
)
if not comments:
break

with transaction.atomic():
descriptions = [
Description(
created_at=comment.created_at,
updated_at=comment.updated_at,
description_json=comment.comment_json,
description_html=comment.comment_html,
description_stripped=comment.comment_stripped,
project_id=comment.project_id,
created_by_id=comment.created_by_id,
updated_by_id=comment.updated_by_id,
workspace_id=comment.workspace_id,
)
for comment in comments
]

created_descriptions = Description.objects.bulk_create(descriptions)

comments_to_update = []
for comment, description in zip(comments, created_descriptions):
comment.description_id = description.id
comments_to_update.append(comment)

IssueComment.objects.bulk_update(comments_to_update, ["description_id"])

self.stdout.write(self.style.SUCCESS("Successfully Copied IssueComment to Description"))
19 changes: 19 additions & 0 deletions apps/api/plane/db/migrations/0109_issuecomment_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.22 on 2025-11-06 08:28

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('db', '0108_alter_issueactivity_issue_comment'),
]

operations = [
migrations.AddField(
model_name='issuecomment',
name='description',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='issue_comment_description', to='db.description'),
),
]
45 changes: 44 additions & 1 deletion apps/api/plane/db/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from plane.utils.exception_logger import log_exception
from .project import ProjectBaseModel
from plane.utils.uuid import convert_uuid_to_integer
from .description import Description


def get_default_properties():
Expand Down Expand Up @@ -446,6 +447,9 @@ class IssueComment(ProjectBaseModel):
comment_stripped = models.TextField(verbose_name="Comment", blank=True)
comment_json = models.JSONField(blank=True, default=dict)
comment_html = models.TextField(blank=True, default="<p></p>")
description = models.OneToOneField(
"db.Description", on_delete=models.CASCADE, related_name="issue_comment_description", null=True
)
attachments = ArrayField(models.URLField(), size=10, blank=True, default=list)
issue = models.ForeignKey(Issue, on_delete=models.CASCADE, related_name="issue_comments")
# System can also create comment
Expand All @@ -466,7 +470,46 @@ class IssueComment(ProjectBaseModel):

def save(self, *args, **kwargs):
self.comment_stripped = strip_tags(self.comment_html) if self.comment_html != "" else ""
return super(IssueComment, self).save(*args, **kwargs)
is_creating = self._state.adding or not self.pk

if not is_creating:
old_issue_comment = IssueComment.objects.get(pk=self.id)

super(IssueComment, self).save(*args, **kwargs)

description_defaults = {
"workspace_id": self.workspace_id,
"project_id": self.project_id,
"created_by_id": self.created_by_id,
"updated_by_id": self.updated_by_id,
"description_stripped": self.comment_stripped,
"description_json": self.comment_json,
"description_html": self.comment_html,
}

if is_creating:
description = Description.objects.create(**description_defaults)

self.description_id = description.id
super(IssueComment, self).save(update_fields=["description_id"])
else:
changed_fields = {}

if old_issue_comment.comment_html != self.comment_html:
changed_fields["description_html"] = self.comment_html

if old_issue_comment.comment_stripped != self.comment_stripped:
changed_fields["description_stripped"] = self.comment_stripped

if old_issue_comment.comment_json != self.comment_json:
changed_fields["description_json"] = self.comment_json

if changed_fields:
if self.description_id:
Description.objects.filter(pk=self.description_id).update(**changed_fields)
else:
description = Description.objects.create(**description_defaults)
IssueComment.objects.filter(pk=self.pk).update(description_id=description.id)

class Meta:
verbose_name = "Issue Comment"
Expand Down
Loading
Loading