aboutsummaryrefslogtreecommitdiff
path: root/store/migrations/0002_create_superuser.py
diff options
context:
space:
mode:
authorMole Shang <135e2@135e2.dev>2026-01-24 19:47:41 +0800
committerMole Shang <135e2@135e2.dev>2026-01-24 19:47:41 +0800
commitb45660fbcf5dd22188354bfa0193845e568bda53 (patch)
tree172825ef6e210ce03fc2241395c6cbc389538a2b /store/migrations/0002_create_superuser.py
downloadseu-bookstore-b45660fbcf5dd22188354bfa0193845e568bda53.tar.gz
seu-bookstore-b45660fbcf5dd22188354bfa0193845e568bda53.tar.bz2
seu-bookstore-b45660fbcf5dd22188354bfa0193845e568bda53.zip
initial commit
Diffstat (limited to 'store/migrations/0002_create_superuser.py')
-rw-r--r--store/migrations/0002_create_superuser.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/store/migrations/0002_create_superuser.py b/store/migrations/0002_create_superuser.py
new file mode 100644
index 0000000..4f322d6
--- /dev/null
+++ b/store/migrations/0002_create_superuser.py
@@ -0,0 +1,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),
+ ]