# Generated by Django 3.1.2 on 2020-10-03 17:37

from django.apps.registry import Apps
from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


def update_name_temp(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
    OAuth2Provider = apps.get_model("authentik_providers_oauth2", "OAuth2Provider")
    db_alias = schema_editor.connection.alias

    for provider in OAuth2Provider.objects.using(db_alias).all():
        provider.name_temp = provider.name
        provider.save()


class Migration(migrations.Migration):
    dependencies = [
        ("authentik_core", "0011_provider_name_temp"),
        ("authentik_providers_oauth2", "0005_auto_20200920_1240"),
    ]

    operations = [
        migrations.RunPython(update_name_temp),
        migrations.RemoveField(
            model_name="oauth2provider",
            name="name",
        ),
    ]
