# Generated by Django 3.2.16 on 2023-01-23 23:39

from django.db import migrations, models


def make_slug_unique(apps, schema_editor):
    Organization = apps.get_model("judge", "Organization")
    slugs = Organization.objects.values_list("slug", flat=True)
    slugs = set([i.lower() for i in slugs])
    for slug in slugs:
        orgs = Organization.objects.filter(slug=slug)
        if len(orgs) > 1:
            for org in orgs:
                org.slug += "-" + str(org.id)
                org.save()


class Migration(migrations.Migration):

    dependencies = [
        ("judge", "0144_auto_20230103_0523"),
    ]

    operations = [
        migrations.RunPython(make_slug_unique, migrations.RunPython.noop, atomic=True),
        migrations.AlterField(
            model_name="organization",
            name="slug",
            field=models.SlugField(
                help_text="Organization name shown in URL",
                max_length=128,
                unique=True,
                verbose_name="organization slug",
            ),
        ),
    ]
