#!/bin/sh

cd source

# Collect static files
echo "system check"
uv run  manage.py check
echo

# not needed in DEV mode
# echo "Collect static files"
# uv run manage.py collectstatic --clear --noinput
# echo


echo "Apply database migrations"
uv run manage.py migrate
echo

echo "Create cache tables"
uv run manage.py createcachetable
echo


echo "Compile messages (translations)"
uv run manage.py compilemessages -v 0
# verbose 0 is silent
echo


# not needed in DEV mode with auth forced
# echo "Create admin superuser if absent"
# uv run manage.py createsuperuser --no-input --username admin
# echo

uv run manage.py cavaliba start
echo

# Start DEV server
echo "Starting DEV server"
#export CAVALIBA_AUTH_MODE=forced
uv run python manage.py runserver 127.0.0.1:8000
#gunicorn core.wsgi:application --bind 0.0.0.0:8000 --log-level info --workers 4 --max-requests 500 --access-logfile '-' --error-logfile '-' --graceful-timeout 2
# uv run gunicorn core.wsgi:application --bind 0.0.0.0:8000 
