# Generated by Django 5.2 on 2025-06-12 09:58

import uuid
from django.conf import settings
from django.db import migrations, models


def gen_team_uuid(apps, schema_editor):
    Team = apps.get_model("core", "Team")
    for row in Team.objects.all():
        row.external_id = uuid.uuid4()
        # Don't need to batch update here, as the table is likely small or empty
        row.save(update_fields=["external_id"])


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0015_alter_accountservice_api_key'),
    ]

    operations = [
        migrations.AddField(
            model_name='team',
            name='external_id',
            field=models.UUIDField(default=uuid.uuid4, editable=False, help_text='Team external UUID for synchronization with external systems', unique=False, verbose_name='external_id'),
        ),
        migrations.RunPython(gen_team_uuid, reverse_code=migrations.RunPython.noop),
        migrations.AlterField(
            model_name='team',
            name='external_id',
            field=models.UUIDField(default=uuid.uuid4, editable=False, help_text='Team external UUID for synchronization with external systems', unique=True, verbose_name='external_id'),
        ),
        #
        migrations.AlterField(
            model_name='team',
            name='users',
            field=models.ManyToManyField(related_name='teams', through='core.TeamAccess', through_fields=('team', 'user'), to=settings.AUTH_USER_MODEL),
        ),
    ]
