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

from django.db import migrations


def convert_nulls_to_empty(apps, schema_editor):
    DataSchema = apps.get_model('app_data', 'DataSchema')
    for field in ['displayname', 'dataformat_ext', 'default_value', 'page']:
        DataSchema.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    DataClass = apps.get_model('app_data', 'DataClass')
    for field in ['displayname', 'page', 'options', 'p_create', 'p_read', 'p_update', 'p_delete', 'p_admin']:
        DataClass.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    DataInstance = apps.get_model('app_data', 'DataInstance')
    for field in ['classname', 'displayname', 'data_json', 'p_read', 'p_update', 'p_delete']:
        DataInstance.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    DataRegistry = apps.get_model('app_data', 'DataRegistry')
    DataRegistry.objects.filter(value__isnull=True).update(value='')

    DataEAV = apps.get_model('app_data', 'DataEAV')
    for field in ['displayname', 'fieldname', 'format', 'value', 'p_read']:
        DataEAV.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    DataFile = apps.get_model('app_data', 'DataFile')
    for field in ['displayname', 'filepath', 'p_read', 'p_write', 'hash']:
        DataFile.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    DataRevision = apps.get_model('app_data', 'DataRevision')
    for field in ['username', 'displayname', 'action']:
        DataRevision.objects.filter(**{f'{field}__isnull': True}).update(**{field: ''})

    DataTask = apps.get_model('app_data', 'DataTask')
    DataTask.objects.filter(singleton__isnull=True).update(singleton='')


def reverse_convert(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('app_data', '0034_alter_dataschema_dataformat'),
    ]

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