team-3/start_db.sh

45 lines
1.8 KiB
Bash
Raw Normal View History

#!/bin/bash
2025-08-01 22:47:40 +02:00
set -e
source ./.env/bin/activate
export C3NAV_DATABASE=postgres://mindshub:test@localhost:5432/insignorocketdb
export C3NAV_DEBUG=True
if [[ $# == 1 ]] && [[ $1 == "stop" ]]; then
echo "Just stopping the postgres container"
2025-08-01 22:42:23 +02:00
sudo docker stop postgres
sudo docker container rm -f postgres
2025-08-01 22:47:40 +02:00
echo "Stopped the postgres container"
2025-08-01 22:42:23 +02:00
elif [[ $# == 1 ]] && [[ $1 == "db" ]]; then
2025-08-01 22:47:40 +02:00
echo "Setting up database"
2025-08-01 22:42:23 +02:00
sudo docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=test -e POSTGRES_USER=mindshub postgres
until psql "postgres://mindshub:test@localhost:5432" <<< "CREATE DATABASE insignorocketdb;"; do
sleep 0.5;
done;
psql "postgres://mindshub:test@localhost:5432/insignorocketdb" < auth_user.sql
psql "postgres://mindshub:test@localhost:5432/insignorocketdb" < dump.sql
pushd src
python manage.py migrate
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | python manage.py shell
popd
2025-08-01 22:47:40 +02:00
echo "Successfully setup database"
2025-08-01 22:42:23 +02:00
elif [[ $# == 1 ]] && [[ $1 == "run" ]]; then
2025-08-01 22:47:40 +02:00
echo "Processing updates and running server"
2025-08-01 22:42:23 +02:00
pushd src
python manage.py processupdates
python manage.py runserver
popd
2025-08-02 00:38:51 +02:00
elif [[ $# == 1 ]] && [[ $1 == "run_without_output" ]]; then
echo "Processing updates and running server without output"
pushd src 2>&1 > /dev/null
python manage.py processupdates 2>&1 | (grep -e "^ERROR" -e "^WARNING" -e "^HTTP" || true)
python manage.py runserver 2>&1 | (grep -e "^ERROR" -e "^WARNING" -e "^HTTP" || true)
popd 2>&1 > /dev/null
2025-08-01 23:33:35 +02:00
elif [[ $# > 0 ]] && [[ $1 == "manage" ]]; then
pushd src
python manage.py "${@:2}"
popd
2025-08-01 22:47:40 +02:00
else
2025-08-02 00:38:51 +02:00
echo "Usage: $0 [stop|db|run|run_without_output|manage]"
fi