# Generated by Django 6.0.6 on 2026-08-07 14:26

from django.db import migrations, models

from club.services.images import get_image_dimensions


def backfill_logo_dimensions(apps, schema_editor):
    """Existing sponsors uploaded a logo before these fields existed, so
    Sponsor.save()'s new dimension computation never ran for them."""
    Sponsor = apps.get_model("club", "Sponsor")
    for sponsor in Sponsor.objects.exclude(logo=""):
        width, height = get_image_dimensions(sponsor.logo)
        Sponsor.objects.filter(pk=sponsor.pk).update(logo_width=width, logo_height=height)


class Migration(migrations.Migration):

    dependencies = [
        ('club', '0019_sponsor'),
    ]

    operations = [
        migrations.AddField(
            model_name='sponsor',
            name='logo_height',
            field=models.PositiveIntegerField(blank=True, editable=False, null=True, verbose_name='logo height'),
        ),
        migrations.AddField(
            model_name='sponsor',
            name='logo_width',
            field=models.PositiveIntegerField(blank=True, editable=False, null=True, verbose_name='logo width'),
        ),
        migrations.RunPython(backfill_logo_dimensions, migrations.RunPython.noop),
    ]
