# Generated by Django 4.0.1 on 2022-03-02 08:20

from django.db import migrations


def UpdateJobStatus(apps, schema_editor):
    """A bug resulted in the human readable choices values for Job.status being saved in the
    database. This migration updates all existing job records to ensure that the correct
    values are present.
    """
    Job = apps.get_model("main", "Job")
    mapping = {"Completed": "C", "Queueing": "Q", "Running": "R"}
    for job in Job.objects.all():
        try:
            job.status = mapping[job.status]
        except KeyError:
            pass
        job.save()


class Migration(migrations.Migration):

    dependencies = [
        ("main", "0013_auto_20210810_2154"),
    ]

    operations = [migrations.RunPython(UpdateJobStatus)]
