#!/bin/sh
set -e

# App must never fail startup due to missing DB/config.
# If DATABASE_URL present, try migrations + seed, but continue even if they fail.
if [ -n "$DATABASE_URL" ]; then
  echo "[entrypoint] DATABASE_URL detected. Attempting prisma generate/migrate/seed (non-fatal on failure)..."
  (npm run db:generate && npm run db:deploy && npm run db:seed) || echo "[entrypoint] Prisma init skipped/failed; continuing to start server."
else
  echo "[entrypoint] DATABASE_URL not set. Skipping prisma. Starting server..."
fi

npm start
