# Generated by Django 3.1.7 on 2024-05-21 12:10

import pytz
from django.db import migrations

TASK = "thunderstore.repository.tasks.update_chunked_package_caches"


def forwards(apps, schema_editor):
    CrontabSchedule = apps.get_model("django_celery_beat", "CrontabSchedule")
    PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask")

    schedule, _ = CrontabSchedule.objects.get_or_create(
        minute="0",
        hour="*",
        day_of_week="*",
        day_of_month="*",
        month_of_year="*",
        timezone=pytz.timezone("UTC"),
    )

    PeriodicTask.objects.get_or_create(
        crontab=schedule,
        name="Update APIV1ChunkedPackageCache",
        task=TASK,
        expire_seconds=300,
    )


def backwards(apps, schema_editor):
    PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask")
    PeriodicTask.objects.filter(task=TASK).delete()


class Migration(migrations.Migration):
    dependencies = [
        ("repository", "0052_add_chunked_package_cache"),
        ("django_celery_beat", "0014_remove_clockedschedule_enabled"),
    ]

    operations = [
        migrations.RunPython(forwards, backwards),
    ]
