From 176e184220244df0db047e94b947f615e6c31af5 Mon Sep 17 00:00:00 2001 From: NarayanBavisetti Date: Wed, 15 Nov 2023 17:18:21 +0530 Subject: [PATCH] fix: back migration of page blocks --- .../db/migrations/0048_auto_20231115_0916.py | 65 +++++++++++++++++++ apiserver/plane/db/models/issue.py | 18 ----- 2 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 apiserver/plane/db/migrations/0048_auto_20231115_0916.py diff --git a/apiserver/plane/db/migrations/0048_auto_20231115_0916.py b/apiserver/plane/db/migrations/0048_auto_20231115_0916.py new file mode 100644 index 000000000..2c47a9152 --- /dev/null +++ b/apiserver/plane/db/migrations/0048_auto_20231115_0916.py @@ -0,0 +1,65 @@ +# Generated by Django 4.2.5 on 2023-11-15 09:16 +# Python imports +import uuid + +from django.db import migrations + +def update_pages(apps, schema_editor): + try: + Page = apps.get_model("db", "Page") + PageBlock = apps.get_model("db", "PageBlock") + PageLog = apps.get_model("db", "PageLog") + + updated_pages = [] + page_logs = [] + + # looping through all the pages + for page in Page.objects.all(): + page_blocks = PageBlock.objects.filter( + page=page.id, project_id=page.project_id, workspace_id=page.workspace_id + ).order_by("sort_order") + + if page_blocks: + # looping through all the page blocks in a page + for page_block in page_blocks: + + # adding the page block name and description to the page description + page.description_html += f"

{page_block.name}

" + page.description_html += page_block.description_html + + if page_block.issue is not None: + # create the page transaction for the issue + page_logs.append( + PageLog( + page_id=page_block.page_id, + transaction=uuid.uuid4().hex, + entity_identifier=page_block.issue_id, + entity_name="issue", + project_id=page.project_id, + workspace_id=page.workspace_id, + created_by_id=page_block.created_by_id, + updated_by_id=page_block.updated_by_id, + ) + ) + updated_pages.append(page) + + Page.objects.bulk_update( + updated_pages, + ["description_html"], + batch_size=100, + ) + PageLog.objects.bulk_create(page_logs, batch_size=100) + + except Exception as e: + print(e) + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0047_issuemention_pagelog_page_archived_at_page_is_locked_and_more'), + ] + + operations = [ + migrations.RunPython(update_pages), + ] \ No newline at end of file diff --git a/apiserver/plane/db/models/issue.py b/apiserver/plane/db/models/issue.py index cd8cf6ea0..406bd5275 100644 --- a/apiserver/plane/db/models/issue.py +++ b/apiserver/plane/db/models/issue.py @@ -132,25 +132,7 @@ class Issue(ProjectBaseModel): self.state = default_state except ImportError: pass - # else: - # try: - # from plane.db.models import State, PageBlock - # # Check if the current issue state and completed state id are same - # if self.state.group == "completed": - # self.completed_at = timezone.now() - # # check if there are any page blocks - # PageBlock.objects.filter(issue_id=self.id).filter().update( - # completed_at=timezone.now() - # ) - # else: - # PageBlock.objects.filter(issue_id=self.id).filter().update( - # completed_at=None - # ) - # self.completed_at = None - - except ImportError: - pass if self._state.adding: # Get the maximum display_id value from the database last_id = IssueSequence.objects.filter(project=self.project).aggregate(