from django.db import migrations
from django.db.models import F


def backfill(apps, schema_editor):
    """Tasks created before the assignment notice existed count as already seen."""
    Task = apps.get_model("tasks", "Task")
    Task.objects.filter(assigned_at__isnull=True).update(assigned_at=F("created_at"), assignee_seen_at=F("created_at"))


class Migration(migrations.Migration):
    dependencies = [("tasks", "0002_task_assigned_at_task_assignee_seen_at_and_more")]
    operations = [migrations.RunPython(backfill, migrations.RunPython.noop)]