-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from neutrons/flush_db_fix
Remove database flush command to make database persistent
- Loading branch information
Showing
4 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
22
live_data_server/plots/management/commands/ensure_adminuser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |