# Generated by Django 3.2.14 on 2022-07-22 05:15
from django.db import migrations


INITIAL_CRON_FUNCTION = ['turnkey_wrapper.crontabs.polling_ei_turnkey_batch', ]

def forward(apps, schema_editor):
    SelectOption = apps.get_model('crontab_monitor', 'SelectOption')
    Inspection = apps.get_model('crontab_monitor', 'Inspection')
    for value in INITIAL_CRON_FUNCTION:
        cf_so = SelectOption(swarm='cron-function', value=value)
        cf_so.save()

    insp = Inspection(
        cron_format='*/15 * * * *',
        name="polling_ei_turnkey_batch",
        function_option=cf_so,
        function_note="Polling EITurnkeyBatch"
    )
    insp.save()


def backward(apps, schema_editor):
    SelectOption = apps.get_model('crontab_monitor', 'SelectOption')
    Inspection = apps.get_model('crontab_monitor', 'Inspection')
    insp = Inspection.objects.filter(name="polling_ei_turnkey_batch",
                                     function_option__value__in=INITIAL_CRON_FUNCTION)
    insp.delete()

    cf_sos = SelectOption.objects.filter(swarm='cron-function', value__in=INITIAL_CRON_FUNCTION)
    cf_sos.delete()



class Migration(migrations.Migration):

    dependencies = [
        ('crontab_monitor', '0004_auto_20220328_1408'),
        ('turnkey_wrapper', '0010_auto_20220722_0343'),
    ]

    operations = [
        migrations.RunPython(forward, backward),
    ]
