From a0444abc21d379ed17a88e69d816768955e3668e Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 13 Oct 2023 17:53:26 +0530 Subject: [PATCH] make invoice_id unique for AppUserTransaction --- app_users/models.py | 3 +-- scripts/migrate_txns.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app_users/models.py b/app_users/models.py index 6341ed651..e594ab72c 100644 --- a/app_users/models.py +++ b/app_users/models.py @@ -212,13 +212,12 @@ class AppUserTransaction(models.Model): user = models.ForeignKey( "AppUser", on_delete=models.CASCADE, related_name="transactions" ) - invoice_id = models.CharField(max_length=255) + invoice_id = models.CharField(max_length=255, unique=True) amount = models.IntegerField() end_balance = models.IntegerField() created_at = models.DateTimeField(editable=False, blank=True, default=timezone.now) class Meta: - unique_together = ["user", "invoice_id"] verbose_name = "Transaction" def __str__(self): diff --git a/scripts/migrate_txns.py b/scripts/migrate_txns.py index 47ef64258..d29150861 100644 --- a/scripts/migrate_txns.py +++ b/scripts/migrate_txns.py @@ -7,9 +7,9 @@ def run(): - with ThreadPoolExecutor(1000) as pool: + with ThreadPoolExecutor(500) as pool: for user in AppUser.objects.all(): - step1(pool, user.id, user.uid) + pool.submit(step1, pool, user.id, user.uid) def step1(pool: ThreadPoolExecutor, user_id: int, uid: str):