#!/bin/sh

set -e

{% if is_postgresql %}
if [ "$DATABASE" = "postgres" ]
then
    echo "Waiting for postgres..."

    while ! nc -z $DB_HOST $DB_PORT; do
      sleep 0.1
    done

    echo "PostgreSQL started"
fi
{% endif %}

# Apply database migrations
python manage.py migrate

exec "$@"
