Skip to content

Commit

Permalink
Merge pull request #16 from neutrons/flush_db_fix
Browse files Browse the repository at this point in the history
Remove database flush command to make database persistent
  • Loading branch information
backmari authored Jun 14, 2024
2 parents 8f377b2 + 3f901ec commit 1795b7e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ cd /var/www/livedata/app
python manage.py collectstatic --noinput

# migrate django models
python manage.py flush --no-input
python manage.py makemigrations --noinput
python manage.py migrate --noinput

# create superuser
echo "from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SUPERUSER_USERNAME}', '${DJANGO_SUPERUSER_USERNAME}@example.com', '${DJANGO_SUPERUSER_PASSWORD}')" | python manage.py shell
#echo "from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SUPERUSER_USERNAME}', '${DJANGO_SUPERUSER_USERNAME}@example.com', '${DJANGO_SUPERUSER_PASSWORD}')" | python manage.py shell

# Create the webcache
python manage.py createcachetable webcache
python manage.py ensure_adminuser --username=${DJANGO_SUPERUSER_USERNAME} --email='[email protected]' --password=${DJANGO_SUPERUSER_PASSWORD}

# run application
gunicorn live_data_server.wsgi:application -w 2 -b :8000 --reload
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions live_data_server/plots/management/commands/ensure_adminuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# taken from
# https://stackoverflow.com/questions/39744593/how-to-create-a-django-superuser-if-it-doesnt-exist-non-interactively
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = "Creates an admin user non-interactively if it doesn't exist"

def add_arguments(self, parser):
parser.add_argument("--username", help="Admin's username")
parser.add_argument("--email", help="Admin's email")
parser.add_argument("--password", help="Admin's password")

def handle(self, *args, **options):
User = get_user_model()
if not User.objects.filter(username=options["username"]).exists():
User.objects.create_superuser(
username=options["username"],
email=options["email"],
password=options["password"],
)

0 comments on commit 1795b7e

Please sign in to comment.