# Generated by Django 2.2.13 on 2021-03-19 20:17
from arches.app.models.fields.i18n import I18n_TextField
from django.db import migrations
from django.conf import settings


class Migration(migrations.Migration):

    dependencies = [
        ("models", "8770_bulk_index_queue_insert"),
    ]

    sql = """
        SET CONSTRAINTS ALL IMMEDIATE;
        UPDATE public.cards SET name=json_build_object('{0}', name);
        UPDATE public.cards SET description=json_build_object('{0}', description);
        UPDATE public.cards SET instructions=json_build_object('{0}', instructions);
        UPDATE public.cards SET helptitle=json_build_object('{0}', helptitle);
        UPDATE public.cards SET helptext=json_build_object('{0}', helptext);
        SET CONSTRAINTS ALL DEFERRED;
    """.format(
        settings.LANGUAGE_CODE
    )

    reverse_sql = """
        UPDATE public.cards SET name=name::jsonb->>'{0}'::text;
        UPDATE public.cards SET description=description::jsonb->>'{0}'::text;
        UPDATE public.cards SET instructions=instructions::jsonb->>'{0}'::text;
        UPDATE public.cards SET helptitle=helptitle::jsonb->>'{0}'::text;
        UPDATE public.cards SET helptext=helptext::jsonb->>'{0}'::text;
    """.format(
        settings.LANGUAGE_CODE
    )

    operations = [
        migrations.RunSQL(sql, reverse_sql),
        migrations.AlterField(
            model_name="cardmodel",
            name="name",
            field=I18n_TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="cardmodel",
            name="description",
            field=I18n_TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="cardmodel",
            name="instructions",
            field=I18n_TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="cardmodel",
            name="helptitle",
            field=I18n_TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="cardmodel",
            name="helptext",
            field=I18n_TextField(blank=True, null=True),
        ),
    ]
