#!/bin/bash
set -e

echo "🔄 Running database migrations..."

# Run any migration scripts that exist
for script in /app/migrations/*.py; do
    if [ -f "$script" ]; then
        echo "  Running: $(basename $script)"
        python "$script" || echo "  ⚠️ Migration $script failed (may already be applied)"
    fi
done

echo "✅ Migrations complete. Starting server..."

# Start the main application with production settings
exec uvicorn main:app --host 0.0.0.0 --port 8000 --root-path /api --proxy-headers --forwarded-allow-ips '*'
