Skip to content

Commit

Permalink
Merge pull request #228 from seanmorley15/development
Browse files Browse the repository at this point in the history
chore: Improve superuser creation logic
  • Loading branch information
seanmorley15 authored Aug 17, 2024
2 parents 1fcb821 + 175a237 commit 816e0c0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 816e0c0

Please sign in to comment.