# Generated by Django 2.2.16 on 2020-10-30 20:56

from django.db import migrations, models


def family_migration_prep(apps, schema_editor):
    Family = apps.get_model("membership", "Family")
    fields = ("name", "pack_comments")

    for field in fields:
        filter_param = {"{}__isnull".format(field): True}
        update_param = {field: ""}
        Family.objects.filter(**filter_param).update(**update_param)


def member_migration_prep(apps, schema_editor):
    Member = apps.get_model("membership", "Member")
    fields = ("gender", "middle_name", "nickname", "pack_comments", "slug", "suffix")

    for field in fields:
        filter_param = {"{}__isnull".format(field): True}
        update_param = {field: ""}
        Member.objects.filter(**filter_param).update(**update_param)


def scout_migration_prep(apps, schema_editor):
    Scout = apps.get_model("membership", "Scout")
    fields = ("member_comments", "reference")

    for field in fields:
        filter_param = {"{}__isnull".format(field): True}
        update_param = {field: ""}
        Scout.objects.filter(**filter_param).update(**update_param)


class Migration(migrations.Migration):

    dependencies = [
        ("membership", "0001_initial"),
    ]

    operations = [
        migrations.RunPython(family_migration_prep, migrations.RunPython.noop),
        migrations.RunPython(member_migration_prep, migrations.RunPython.noop),
        migrations.RunPython(scout_migration_prep, migrations.RunPython.noop),
    ]
