# Generated by Django 3.2 on 2021-04-13 12:32

from django.db import migrations


def populate_new_identifier(apps, schema_editor):
    Picture = apps.get_model("terra_opp", "Picture")

    for picture in Picture.objects.all():
        if picture.old_identifier:
            picture.identifier = str(picture.old_identifier)
            picture.save()


def populate_old_identifier(apps, schema_editor):
    Picture = apps.get_model("terra_opp", "Picture")

    for picture in Picture.objects.all():
        if picture.identifier:
            picture.old_identifier = int(picture.identifier)
            picture.save()


class Migration(migrations.Migration):

    dependencies = [
        ("terra_opp", "0012_picture_identifier_to_charfield"),
    ]

    operations = [
        migrations.RunPython(
            code=populate_new_identifier,
            reverse_code=populate_old_identifier,
        ),
        migrations.RemoveField(
            model_name="picture",
            name="old_identifier",
        ),
    ]
