Refactor TimeBasedDrop constraints to ensure required_minutes_watched is non-negative

This commit is contained in:
Joakim Hellsén 2025-09-05 01:04:25 +02:00
commit 7d81b1a1b5
2 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,21 @@
# Generated by Django 5.2.5 on 2025-09-04 23:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('twitch', '0010_alter_dropbenefit_id_alter_game_id_and_more'),
]
operations = [
migrations.RemoveConstraint(
model_name='timebaseddrop',
name='drop_positive_minutes',
),
migrations.AddConstraint(
model_name='timebaseddrop',
constraint=models.CheckConstraint(condition=models.Q(('required_minutes_watched__isnull', True), ('required_minutes_watched__gte', 0), _connector='OR'), name='drop_positive_minutes'),
),
]

View file

@ -424,9 +424,9 @@ class TimeBasedDrop(models.Model):
condition=models.Q(start_at__isnull=True) | models.Q(end_at__isnull=True) | models.Q(end_at__gt=models.F("start_at")),
name="drop_valid_date_range",
),
# Ensure required_minutes_watched is positive when set
# Ensure required_minutes_watched is non-negative when set
models.CheckConstraint(
condition=models.Q(required_minutes_watched__isnull=True) | models.Q(required_minutes_watched__gt=0), name="drop_positive_minutes"
condition=models.Q(required_minutes_watched__isnull=True) | models.Q(required_minutes_watched__gte=0), name="drop_positive_minutes"
),
]
indexes: ClassVar[list] = [