# Generated by Django 3.0.8 on 2020-07-31 10:05

import json

from django.db import migrations


def migrate_confirm_text(apps, schema_editor):
    # We now allow creating multiple confirm texts so we migrate the setting for that
    # from `confirm_text` to `confirm_texts`
    Event_SettingsStore = apps.get_model('pretixbase', 'Event_SettingsStore')
    for store in Event_SettingsStore.objects.filter(key="confirm_text"):
        if store.value:
            values = json.dumps([json.loads(store.value)])  # convert single value to one-element list
            store.key = "confirm_texts"
            store.value = values
            store.save()


class Migration(migrations.Migration):

    dependencies = [
        ('pretixbase', '0159_mails_by_sales_channel'),
    ]

    operations = [
        migrations.RunPython(migrate_confirm_text, migrations.RunPython.noop),
    ]
