# Generated by Django 5.2.12 on 2026-05-23 13:49

from django.db import migrations


def convert_nulls_to_empty(apps, schema_editor):
    SireneUser = apps.get_model('app_user', 'SireneUser')
    for field in ['external_id', 'email', 'mobile', 'firstname', 'lastname',
                  'displayname', 'description', 'secondary_email', 'secondary_mobile']:
        SireneUser.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    SireneGroup = apps.get_model('app_user', 'SireneGroup')
    for field in ['displayname', 'description', 'autogroup']:
        SireneGroup.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    SirenePermission = apps.get_model('app_user', 'SirenePermission')
    for field in ['displayname', 'description']:
        SirenePermission.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})


def reverse_convert(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('app_user', '0006_rename_app_user_si_keyname_ed96f2_idx_iam_group_keyname_3abf0f_idx_and_more'),
    ]

    operations = [
        migrations.RunPython(convert_nulls_to_empty, reverse_convert),
    ]
