#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"

echo "==> Removing old node_modules"
rm -rf node_modules

echo "==> Installing dependencies (Prisma pinned to 6.19.3 — do NOT use Prisma 7)"
npm install --omit=dev

echo "==> Generating Prisma client with LOCAL binary (not npx latest)"
./node_modules/.bin/prisma -v
./node_modules/.bin/prisma generate
./node_modules/.bin/prisma db push

echo ""
echo "OK. Restart the Node.js app in cPanel."
echo "Then open: https://backend.bigwesttours.com/health/db"
echo "Expected: {"ok":true,"database":"up"}"
echo "If health/db fails, DATABASE_URL is wrong or MySQL is down."
echo "Login after restart: admin@bigwesttours.com / ChangeMe123!"
