from django.db import migrations


ANONYMOUS_USERNAME = "anonym"


def create_anonymous(apps, schema_editor):
    User = apps.get_model("gaehsnitz", "User")
    User.objects.get_or_create(
        username=ANONYMOUS_USERNAME,
        defaults={"pin": "", "is_staff": False, "is_superuser": False},
    )


def delete_anonymous(apps, schema_editor):
    User = apps.get_model("gaehsnitz", "User")
    User.objects.filter(username=ANONYMOUS_USERNAME).delete()


class Migration(migrations.Migration):
    dependencies = [
        ("gaehsnitz", "0008_alter_drink_category"),
    ]

    operations = [
        migrations.RunPython(create_anonymous, delete_anonymous),
    ]
