# Generated by Django 3.1.13 on 2021-08-23 12:00
from django.contrib.postgres.search import SearchVectorField
from django.db import migrations


SQL = """
UPDATE elus_rechercheparrainage rp
SET search = m.search
FROM data_france_elumunicipal m
WHERE rp.maire_id = m.id;

UPDATE elus_rechercheparrainage rp
SET search = d.search
FROM data_france_eludepartemental d
WHERE rp.elu_departemental_id = d.id;

UPDATE elus_rechercheparrainage rp
SET search = r.search
FROM data_france_eluregional r
WHERE rp.elu_regional_id = r.id;

UPDATE elus_rechercheparrainage rp
SET search = d.search
FROM data_france_depute d
WHERE rp.depute_id = d.id;

UPDATE elus_rechercheparrainage rp
SET search = d.search
FROM data_france_deputeeuropeen d
WHERE rp.depute_europeen_id = d.id;
"""


class Migration(migrations.Migration):
    dependencies = [
        ("elus", "0031_auto_20210727_0031"),
        ("data_france", "0030_indexs_recherche_elus"),
    ]

    operations = [
        migrations.AddField(
            model_name="rechercheparrainage",
            name="search",
            field=SearchVectorField(
                verbose_name="Champ de recherche",
                null=True,
            ),
        ),
        migrations.RunSQL(sql=SQL, reverse_sql=migrations.RunSQL.noop),
    ]
