From 0cb4edab545204f201dd4744d737579cb4aa602d Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Tue, 31 Jan 2023 19:49:02 +0530 Subject: [PATCH] fix: back migration for identifiers without workspaces (#212) --- apiserver/back_migration.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apiserver/back_migration.py b/apiserver/back_migration.py index 33513f15c..57ded0ba4 100644 --- a/apiserver/back_migration.py +++ b/apiserver/back_migration.py @@ -1,5 +1,5 @@ # All the python scripts that are used for back migrations - +from plane.db.models import ProjectIdentifier from plane.db.models import Issue, IssueComment # Update description and description html values for old descriptions @@ -40,3 +40,21 @@ def update_comments(): except Exception as e: print(e) print("Failed") + + +def update_project_identifiers(): + try: + project_identifiers = ProjectIdentifier.objects.filter(workspace_id=None).select_related("project", "project__workspace") + updated_identifiers = [] + + for identifier in project_identifiers: + identifier.workspace_id = identifier.project.workspace_id + updated_identifiers.append(identifier) + + ProjectIdentifier.objects.bulk_update( + updated_identifiers, ["workspace_id"], batch_size=50 + ) + print("Success") + except Exception as e: + print(e) + print("Failed")