Skip to content

Commit

Permalink
feat: default superuser migration
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelovicentegc committed Jun 5, 2020
1 parent 43d90a5 commit ce58974
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions backend/migrations/0004_create_default_superuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from django.db import migrations

class Migration(migrations.Migration):
dependencies = [
('backend', '0003_auto_20200605_0041'),
]

def generate_superuser(apps, schema_editor):
from django.contrib.auth.models import User

SU_NAME = 'admin'

try:
User.objects.get(username=SU_NAME)
except User.DoesNotExist:
SU_EMAIL = 'admin@example.com'
SU_PASSWORD = 'admin'
superuser = User.objects.create_superuser(
username=SU_NAME,
email=SU_EMAIL,
password=SU_PASSWORD)
superuser.is_superuser = True
superuser.is_staff = True
superuser.save()

operations = [
migrations.RunPython(generate_superuser),
]

0 comments on commit ce58974

Please sign in to comment.