# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-30 18:43
from __future__ import unicode_literals

from django.db import migrations


def populate_temp_id(apps, schema_editor):
    SparkJobRunAlert = apps.get_model("jobs", "SparkJobRunAlert")
    alerts = SparkJobRunAlert.objects.all()
    for index, alert in enumerate(alerts, start=1):  # pks starts at 1, not 0
        alert.temp_id = index
        alert.save()


def delete_temp_id(apps, schema_editor):
    SparkJobRunAlert = apps.get_model("jobs", "SparkJobRunAlert")

    for alert in SparkJobRunAlert.objects.all():
        alert.temp_id = None
        alert.save()


class Migration(migrations.Migration):

    dependencies = [("jobs", "0036_sparkjobrunalert_temp_id")]

    operations = [migrations.RunPython(populate_temp_id, delete_temp_id)]
