<gh_stars>0
# Generated by Django 2.1.1 on 2019-01-04 14:05

import os
from django.db import migrations
from getenv import env
from django.contrib.auth import get_user_model
from django.db.utils import IntegrityError



class Migration(migrations.Migration):
    def create_root_user(apps, schema_editor):
        if not env("DJANGO_SUPERUSER_USERNAME", False) or \
            not env("DJANGO_SUPERUSER_USERNAME", False) or \
            not env("DJANGO_SUPERUSER_EMAIL", False):
            print("Misconfigured, initial DJANGO_SUPERUSER_USERNAME, PASSWORD and EMAIL should be in the env.")
        else:
            User = get_user_model()
            try:
                User.objects.create_superuser(env("DJANGO_SUPERUSER_USERNAME"), env("DJANGO_SUPERUSER_EMAIL"), env("DJANGO_SUPERUSER_PASSOWRD"))
            except IntegrityError:
                print("The superuser with this username was already created.")

    dependencies = [
    ]

    operations = [
        migrations.RunPython(create_root_user),
    ]
