aboutsummaryrefslogtreecommitdiff
path: root/store/migrations/0002_create_superuser.py
blob: 4f322d6e827d7511ea082bd9b251479e8bea5e8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.db import migrations
import os

def create_superuser(apps, schema_editor):
    User = apps.get_model('store', 'User')
    db_alias = schema_editor.connection.alias

    if not User.objects.using(db_alias).filter(username='admin').exists():
        User.objects.create_superuser(
            username=os.environ.get('DJANGO_SUPERUSER_USERNAME', 'admin'),
            email=os.environ.get('DJANGO_SUPERUSER_EMAIL', 'admin@example.com'),
            password=os.environ.get('DJANGO_SUPERUSER_PASSWORD', 'admin'),
            is_staff=True,
            is_superuser=True,
            roles=['user', 'admin']
        )

class Migration(migrations.Migration):

    dependencies = [
        ('store', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(create_superuser, migrations.RunPython.noop),
    ]