Skip to content

Commit

Permalink
make invoice_id unique for AppUserTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Oct 13, 2023
1 parent 65e7159 commit a0444ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app_users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions scripts/migrate_txns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a0444ab

Please sign in to comment.