From 175a2371b1e3c67f5bff4b1d7bda8aaac0fb4bd9 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Sat, 17 Aug 2024 08:00:01 -0400 Subject: [PATCH] chore: Improve superuser creation logic --- backend/entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index b72181b2..832da36f 100644 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -19,13 +19,13 @@ python manage.py migrate # Check for default data python manage.py worldtravel-seed -# Create superuser if environment variables are set +# Create superuser if environment variables are set and there are no users present at all. if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ]; then echo "Creating superuser..." python manage.py shell << EOF from django.contrib.auth import get_user_model User = get_user_model() -if not User.objects.filter(username='$DJANGO_ADMIN_USERNAME').exists(): +if User.objects.count() == 0: User.objects.create_superuser('$DJANGO_ADMIN_USERNAME', '$DJANGO_ADMIN_EMAIL', '$DJANGO_ADMIN_PASSWORD') print("Superuser created successfully.") else: