Skip to content

Commit 1795b7e

Browse files
authored
Merge pull request #16 from neutrons/flush_db_fix
Remove database flush command to make database persistent
2 parents 8f377b2 + 3f901ec commit 1795b7e

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ cd /var/www/livedata/app
1313
python manage.py collectstatic --noinput
1414

1515
# migrate django models
16-
python manage.py flush --no-input
1716
python manage.py makemigrations --noinput
1817
python manage.py migrate --noinput
1918

2019
# create superuser
21-
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
20+
#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
2221

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

2626
# run application
2727
gunicorn live_data_server.wsgi:application -w 2 -b :8000 --reload

live_data_server/plots/management/__init__.py

Whitespace-only changes.

live_data_server/plots/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# taken from
2+
# https://stackoverflow.com/questions/39744593/how-to-create-a-django-superuser-if-it-doesnt-exist-non-interactively
3+
from django.contrib.auth import get_user_model
4+
from django.core.management.base import BaseCommand
5+
6+
7+
class Command(BaseCommand):
8+
help = "Creates an admin user non-interactively if it doesn't exist"
9+
10+
def add_arguments(self, parser):
11+
parser.add_argument("--username", help="Admin's username")
12+
parser.add_argument("--email", help="Admin's email")
13+
parser.add_argument("--password", help="Admin's password")
14+
15+
def handle(self, *args, **options):
16+
User = get_user_model()
17+
if not User.objects.filter(username=options["username"]).exists():
18+
User.objects.create_superuser(
19+
username=options["username"],
20+
email=options["email"],
21+
password=options["password"],
22+
)

0 commit comments

Comments
 (0)