# Generated by Django 2.0.8 on 2018-09-13 13:17

import json

import django.contrib.postgres.fields.jsonb
from django.db import migrations

import saleor.core.utils.json_serializer


class Migration(migrations.Migration):
    def populate_data(apps, schema_editor):
        OrderEvent = apps.get_model("order", "OrderEvent")
        for order_event in OrderEvent.objects.all():
            if isinstance(order_event.parameters, str):
                json_str = order_event.parameters
                while isinstance(json_str, str):
                    json_str = json.loads(json_str)
                order_event.parameters_new = json_str
                order_event.save()

    dependencies = [("order", "0056_auto_20180911_1541")]

    operations = [
        migrations.AddField(
            model_name="orderevent",
            name="parameters_new",
            field=django.contrib.postgres.fields.jsonb.JSONField(
                blank=True,
                default=dict,
                encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
            ),
        ),
        migrations.RunPython(populate_data),
    ]
