Skip to content

Commit

Permalink
fix possible conflicts and add constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjp93 committed Oct 12, 2024
1 parent c4e5fba commit 15080ee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.1 on 2024-10-12 20:33

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('match', '0050_remove_match_is_fully_imported_and_more_updated'),
]

operations = [
migrations.AlterUniqueTogether(
name='ban',
unique_together={('team', 'pick_turn')},
),
migrations.AlterUniqueTogether(
name='team',
unique_together={('_id', 'match')},
),
]
6 changes: 6 additions & 0 deletions match/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ class Team(models.Model):
def __str__(self):
return f"Team(match={self.match._id}, _id={self._id})"

class Meta:
unique_together = ("_id", "match")


class Ban(models.Model):
id: int | None
Expand All @@ -885,6 +888,9 @@ class Ban(models.Model):
def __str__(self):
return f"Ban(team={self.team._id}, match={self.team.match._id})"

class Meta:
unique_together = ("team", "pick_turn")


class Bounty(BaseModel):
monster_bounty: int = 0
Expand Down
18 changes: 14 additions & 4 deletions match/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,21 @@ def multi_match_import(matches_json, region):
unique_fields=["_id"],
update_fields=["game_duration"],
)
Participant.objects.bulk_create(participants)
Stats.objects.bulk_create(stats)
Participant.objects.bulk_create(
participants,
update_conflicts=True,
unique_fields=["_id", "match_id"],
update_fields=["champion_id"],
)
Stats.objects.bulk_create(stats, ignore_conflicts=True)
Summoner.objects.bulk_create(summoners, ignore_conflicts=True)
Team.objects.bulk_create(teams)
Ban.objects.bulk_create(bans)
Team.objects.bulk_create(
teams,
update_conflicts=True,
unique_fields=["match_id", "_id"],
update_fields=["win"],
)
Ban.objects.bulk_create(bans, ignore_conflicts=True)


@app.task(name="match.tasks.import_recent_matches")
Expand Down

0 comments on commit 15080ee

Please sign in to comment.