# Generated by Django 4.1.2 on 2023-02-17 23:33

from django.db import migrations


def apply_migration(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Group = apps.get_model("auth", "Group")
    Group.objects.using(db_alias).bulk_create(
        [Group(name="API Users")]
    )
    api_users_group = Group.objects.using(db_alias).get(name="API Users")
    User = apps.get_model("users", "User")
    users = User.objects.filter(username__startswith="api-")
    for user in users:
        user.groups.add(api_users_group)


def revert_migration(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Group.objects.filter(name="API Users").delete()


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0002_load_fixture'),
    ]

    operations = [migrations.RunPython(apply_migration, revert_migration)]
