fix: back migration of page blocks

This commit is contained in:
NarayanBavisetti 2023-11-15 17:18:21 +05:30
parent 73c2416055
commit 176e184220
2 changed files with 65 additions and 18 deletions

View File

@ -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"<p>{page_block.name}</p>"
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),
]

View File

@ -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(