Skip to content

Remove database flush command to make database persistent #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
)
Loading