#!/bin/bash
# ============================================================
# update.sh
# Re-deploy after pushing new code to GitHub
# Run as root on the server
# ============================================================
set -e

GITHUB_TOKEN="ghp_PASTE_YOUR_TOKEN_HERE"
DEPLOY_DIR="/var/www/html/me.goteku.com"
DOMAIN="me.goteku.com"

echo "=== Pulling latest code ==="
cd "${DEPLOY_DIR}"
git pull "https://${GITHUB_TOKEN}@github.com/dsentosa/me.com.git" main

echo "=== Updating backend dependencies ==="
cd "${DEPLOY_DIR}/backend"
source venv/bin/activate
pip install -r requirements.txt --quiet
alembic upgrade head
deactivate

echo "=== Rebuilding frontend ==="
cd "${DEPLOY_DIR}/frontend"
npm install --quiet
npm run build

echo "=== Restarting backend ==="
systemctl restart me-goteku-backend

echo ""
echo "✅ Update complete! https://${DOMAIN}"
