From eba0f02aebba873de15a09baf3fc5b1bbb311360 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Sat, 18 Feb 2023 12:29:46 +0530 Subject: [PATCH] feat: back migration script to populate random sort_order values --- apiserver/back_migration.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/apiserver/back_migration.py b/apiserver/back_migration.py index 9613412a3..f716ea29f 100644 --- a/apiserver/back_migration.py +++ b/apiserver/back_migration.py @@ -1,8 +1,9 @@ # All the python scripts that are used for back migrations import uuid +import random +from django.contrib.auth.hashers import make_password from plane.db.models import ProjectIdentifier from plane.db.models import Issue, IssueComment, User -from django.contrib.auth.hashers import make_password # Update description and description html values for old descriptions @@ -79,3 +80,19 @@ def update_user_empty_password(): except Exception as e: print(e) print("Failed") + + +def updated_issue_sort_order(): + try: + issues = Issue.objects.all() + updated_issues = [] + + for issue in issues: + issue.sort_order = issue.sequence_id * random.randint(100, 500) + updated_issues.append(issue) + + Issue.objects.bulk_update(updated_issues, ["sort_order"], batch_size=100) + print("Success") + except Exception as e: + print(e) + print("Failed")