#!/bin/sh
set -e

echo "Starting Phosphat Report Application..."

# Run database migrations
echo "Running database migrations..."
npx prisma db push --accept-data-loss

# Run seed using production script
echo "Seeding database..."
if [ -f "scripts/seed-production.js" ]; then
    echo "Using production seed script..."
    node scripts/seed-production.js
else
    echo "Production seed script not found, trying alternative methods..."
    if [ -f "prisma/seed.js" ]; then
        echo "Using JavaScript seed file..."
        node prisma/seed.js
    else
        echo "No seeding method available, skipping..."
    fi
fi

echo "Database setup complete. Starting application on port 3000..."
export PORT=3000
exec npx remix-serve ./build/server/index.js