#!/usr/bin/env bash set -e # Resolve DB host/port from vars or defaults DB_HOST="${DB_HOST:-${MYSQL_HOST:-db}}" DB_PORT="${DB_PORT:-${MYSQL_PORT:-3306}}" echo "[⏳] Waiting for database at $DB_HOST:$DB_PORT..." until nc -z "$DB_HOST" "$DB_PORT"; do sleep 1 done echo "[✔] Database is up" # Only the "flask" entrypoint needs uploads + migrations if [ "$1" = "flask" ]; then # Prepare upload dir (web only) UPLOAD_DIR="/app/${UPLOAD_FOLDER:-static/uploads}" mkdir -p "$UPLOAD_DIR" chown -R 1000:998 "$UPLOAD_DIR" chmod -R 775 "$UPLOAD_DIR" # Run DB migrations echo "[🛠️] Applying database migrations" flask db upgrade # Ensure any missing tables echo "[🛠️] Ensuring tables exist" python <