Skip to content

Commit

Permalink
Add unique constraint for memberships
Browse files Browse the repository at this point in the history
  • Loading branch information
Syriiin committed May 31, 2024
1 parent 4f107c8 commit 60d6d75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions leaderboards/migrations/0021_membership_unique_memberships.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-05-31 14:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("leaderboards", "0020_membershipscore_performance_total_and_more"),
]

operations = [
migrations.AddConstraint(
model_name="membership",
constraint=models.UniqueConstraint(
fields=("leaderboard_id", "user_id"), name="unique_memberships"
),
),
]
6 changes: 6 additions & 0 deletions leaderboards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ def __str__(self):
return f"{self.leaderboard}: {self.user.username}"

class Meta:
constraints = [
models.UniqueConstraint(
fields=["leaderboard_id", "user_id"], name="unique_memberships"
)
]

indexes = [models.Index(fields=["leaderboard"]), models.Index(fields=["user"])]


Expand Down

0 comments on commit 60d6d75

Please sign in to comment.