# Generated manually to set default ISTAT code
from django.db import migrations, models
from django.db.models import Q


def set_default_istat_code(apps, schema_editor):
    Structure = apps.get_model("structures", "Structure")
    Structure.objects.filter(Q(istat_code__isnull=True) | Q(istat_code="")).update(
        istat_code="A12345"
    )


def noop_reverse(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("structures", "0013_structure_istat_code"),
    ]

    operations = [
        migrations.AlterField(
            model_name="structure",
            name="istat_code",
            field=models.CharField(
                blank=True,
                default="A12345",
                help_text="ISTAT structure identification code for export file naming",
                max_length=32,
                null=True,
            ),
        ),
        migrations.RunPython(set_default_istat_code, noop_reverse),
    ]
