# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-03-21 15:07
from __future__ import unicode_literals

from django.db import migrations, models


def port_emr_release_version(apps, schema_editor):
    SparkJobRun = apps.get_model("jobs", "SparkJobRun")

    for run in SparkJobRun.objects.all():
        run.emr_release_version = run.spark_job.emr_release.version
        run.save()


def revert_emr_release_version(apps, schema_editor):
    SparkJobRun = apps.get_model("jobs", "SparkJobRun")

    for run in SparkJobRun.objects.all():
        run.emr_release_version = None
        run.save()


class Migration(migrations.Migration):

    dependencies = [("jobs", "0021_remove_spark_job_emr_release")]

    operations = [
        migrations.AddField(
            model_name="sparkjobrun",
            name="emr_release_version",
            field=models.CharField(blank=True, max_length=50, null=True),
        ),
        migrations.RunPython(port_emr_release_version, revert_emr_release_version),
    ]
