#!/bin/bash
set -e

echo "🚀 Service Finder Pre‑Start Schema Synchronization"
echo "=================================================="

# Ensure we are in the correct directory (should be /app inside container)
cd /app

# Override EMAIL_PROVIDER to smtp for development
export EMAIL_PROVIDER=smtp

# Run the unified database synchronizer with --apply flag
echo "📦 Running unified_db_sync.py --apply..."
python -m app.scripts.unified_db_sync --apply

# Verify that the sync succeeded
if [ $? -eq 0 ]; then
    echo "✅ Schema synchronization completed successfully."
else
    echo "❌ Schema synchronization failed. Exiting."
    exit 1
fi

# Start the FastAPI application
echo "🌐 Starting FastAPI server..."
exec uvicorn app.main:app --host 0.0.0.0 --port 8000