My-Weekly-ToDo-List/scripts/update-server.sh
mARTin 704738777a fix: add missing migrations and fix deploy script failures
- Fix setval(0) error in accountNumber migration (use GREATEST(..., 1))
- Add migration for dateVerticalAlign, dayHeaderGap, weekday settings, quoteLanguages
- Deploy scripts now fall back to db push if migrate deploy fails

v1.22.3
2026-03-10 15:59:37 +01:00

49 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Server Update Script: Pull latest main, build, and restart PM2
set -e # Stop on any error
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
APP_DIR="/root/My-Weekly-ToDo-List"
PM2_NAME="my-weekly-todo"
APP_URL="https://todo.martin-bierschenk.de"
cd "$APP_DIR"
echo -e "${YELLOW}[1/6] Syncing with GitHub (main)...${NC}"
git fetch origin
git reset --hard origin/main # Force-sync, ignores any local changes
echo -e " Version: $(node -p "require('./package.json').version")"
echo -e "${YELLOW}[2/6] Installing dependencies...${NC}"
npm install
echo -e "${YELLOW}[3/6] Running database migrations...${NC}"
npx prisma migrate deploy || {
echo -e "${YELLOW} migrate deploy failed, falling back to db push...${NC}"
npx prisma db push --accept-data-loss
}
npx prisma generate
echo -e "${YELLOW}[4/6] Building application...${NC}"
npm run build
echo -e "${YELLOW}[5/6] Copying static assets to standalone...${NC}"
cp -r public .next/standalone/
mkdir -p .next/standalone/.next/static
cp -r .next/static .next/standalone/.next/
cp .env .next/standalone/ 2>/dev/null || true
cp .env.local .next/standalone/ 2>/dev/null || true
echo -e "${YELLOW}[6/6] Restarting PM2...${NC}"
pm2 delete "$PM2_NAME" 2>/dev/null || true
PORT=3000 NEXTAUTH_URL="$APP_URL" pm2 start .next/standalone/server.js --name "$PM2_NAME"
pm2 save
echo ""
echo -e "${GREEN}✓ Update complete! Running v$(node -p "require('./package.json').version")${NC}"
pm2 list