#!/bin/bash
set -e

echo "=== MusicAnalyser Backend Starting ==="

# Run Alembic migrations
echo "Running database migrations..."
alembic upgrade head

# Start the worker in background (polls Spotify every 60s)
echo "Starting Spotify ingestion worker..."
python run_worker.py &
WORKER_PID=$!

# Start the API server in foreground
echo "Starting API server on port 8000..."
exec uvicorn app.main:app --host 0.0.0.0 --port 8000
