# -*- coding: utf-8 -*-
# Generated by Django 1.11.24 on 2019-10-20 15:27
from __future__ import unicode_literals

from django.db import migrations, models
from django.db.models import Case, When, Value


def migrate_status(apps, schema_editor):
    from river.models import PENDING, APPROVED
    TransitionApproval = apps.get_model('river', 'TransitionApproval')
    TransitionApproval.objects.update(status2=Case(
        When(status=0, then=Value(PENDING)),
        When(status=1, then=Value(APPROVED))
    ))


def reverse_migrate_status(apps, schema_editor):
    from river.models import PENDING, APPROVED
    TransitionApproval = apps.get_model('river', 'TransitionApproval')
    TransitionApproval.objects.update(status=Case(
        When(status2=PENDING, then=Value(0)),
        When(status2=APPROVED, then=Value(1)),
    ))


class Migration(migrations.Migration):
    dependencies = [
        ('river', '0004_auto_20191016_1731'),
    ]

    operations = [
        migrations.AddField(
            model_name='transitionapproval',
            name='status2',
            field=models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved')], default='pending', max_length=100, verbose_name='Status'),
        ),
        migrations.RunPython(migrate_status, reverse_code=reverse_migrate_status),
        migrations.RemoveField(
            model_name='transitionapproval',
            name='status',
        ),
        migrations.RenameField('transitionapproval', 'status2', 'status'),
    ]
