Skip to content

Commit

Permalink
create user and experiment on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
BeritJanssen committed Oct 18, 2023
1 parent f084edd commit c1c36a6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ SQL_PASSWORD=
SQL_HOST=
AML_DEBUG=true
DJANGO_SETTINGS_MODULE=aml.development_settings
DJANGO_SUPERUSER_USERNAME=admin # do not use in production!
DJANGO_SUPERUSER_PASSWORD=admin # do not use in production!
DJANGO_SUPERUSER_EMAIL=mail@example.com # do not use in production!
AML_LOCATION_PROVIDER=http://ip2country:8854
REACT_APP_API_ROOT=http://localhost:8000
REACT_APP_EXPERIMENT_SLUG=
REACT_APP_EXPERIMENT_SLUG=gold-msi
REACT_APP_AML_HOME=https://www.amsterdammusiclab.nl
REACT_APP_LOGO_URL=
REACT_APP_HTML_PAGE_TITLE=Amsterdam Music Lab Experiment
Expand Down
26 changes: 26 additions & 0 deletions backend/experiment/management/commands/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.core import management
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

from experiment.models import Experiment
from section.models import Playlist

class Command(BaseCommand):
""" Command for creating a superuser and an experiment if they do not yet exist """

def handle(self, *args, **options):
if User.objects.count() == 0:
management.call_command('createsuperuser', '--no-input')
logger.info('Created superuser')
if Experiment.objects.count() == 0:
playlist = Playlist.objects.create(
name='Empty Playlist'
)
experiment = Experiment.objects.create(
name='Goldsmiths Musical Sophistication Index',
rules='GOLD_MSI',
slug='gold-msi',
)
experiment.playlists.add(playlist)
print('Created default experiment')

2 changes: 0 additions & 2 deletions backend/manage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
from os.path import join, dirname
from dotenv import load_dotenv
from pathlib import Path

def main():
env_path = join(dirname(__file__), '.env')
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ services:
environment:
- AML_DEBUG=${AML_DEBUG}
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
- DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME}
- DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
- DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL}
- AML_LOCATION_PROVIDER=${AML_LOCATION_PROVIDER}
- SQL_DATABASE=${SQL_DATABASE}
- SQL_USER=${SQL_USER}
- SQL_PASSWORD=${SQL_PASSWORD}
- SQL_HOST=${SQL_HOST}
ports:
- 8000:8000
command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
command: bash -c "python manage.py migrate && python manage.py bootstrap && python manage.py runserver 0.0.0.0:8000"
client:
build:
context: ./frontend
Expand Down

0 comments on commit c1c36a6

Please sign in to comment.