From f70a235c57f92521521f3538d75c7a2cf37108f8 Mon Sep 17 00:00:00 2001 From: mARTin Date: Sun, 1 Mar 2026 15:59:18 +0100 Subject: [PATCH] fix(lxc): refactor boot and update scripts for safe migrations and standalone mode chore(release): bump version to 1.8.6 --- package.json | 2 +- scripts/boot-update.sh | 41 +++++++++++++++++++++++----------------- scripts/update-server.sh | 10 ++++++---- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 93aad7b..c476c5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-weekly-todo-list", - "version": "1.8.5", + "version": "1.8.6", "description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view", "main": "index.js", "scripts": { diff --git a/scripts/boot-update.sh b/scripts/boot-update.sh index 3d21c6a..10992e6 100755 --- a/scripts/boot-update.sh +++ b/scripts/boot-update.sh @@ -16,35 +16,42 @@ log "=== Boot update started ===" cd "$APP_DIR" +# Check and ensure we are on main branch +log "Ensuring main branch..." +git checkout main 2>&1 | tee -a "$LOG_FILE" + # Check if there are remote changes log "Fetching from origin..." git fetch origin main 2>&1 | tee -a "$LOG_FILE" LOCAL=$(git rev-parse HEAD) REMOTE=$(git rev-parse origin/main) +NEXT_DIR="$APP_DIR/.next" -if [ "$LOCAL" = "$REMOTE" ]; then - log "Already up-to-date. No rebuild needed." +if [ "$LOCAL" = "$REMOTE" ] && [ -d "$NEXT_DIR" ]; then + log "Already up-to-date and .next directory exists. No rebuild needed." log "=== Boot update finished (no changes) ===" exit 0 fi -log "Changes detected. Updating from $LOCAL to $REMOTE" +if [ "$LOCAL" != "$REMOTE" ]; then + log "Changes detected. Updating from $LOCAL to "$REMOTE"" + log "Pulling latest changes..." + git pull origin main 2>&1 | tee -a "$LOG_FILE" + + log "Installing dependencies..." + npm install 2>&1 | tee -a "$LOG_FILE" +fi -log "Pulling latest changes..." -git checkout main 2>&1 | tee -a "$LOG_FILE" -git pull origin main 2>&1 | tee -a "$LOG_FILE" +if [ ! -d "$NEXT_DIR" ] || [ "$LOCAL" != "$REMOTE" ]; then + log "Updating database schema (Safe Migrate)..." + npx prisma migrate deploy 2>&1 | tee -a "$LOG_FILE" -log "Installing dependencies..." -npm install 2>&1 | tee -a "$LOG_FILE" + log "Regenerating Prisma client..." + npx prisma generate 2>&1 | tee -a "$LOG_FILE" -log "Updating database schema..." -npx prisma db push 2>&1 | tee -a "$LOG_FILE" + log "Building application..." + npm run build 2>&1 | tee -a "$LOG_FILE" +fi -log "Regenerating Prisma client..." -npx prisma generate 2>&1 | tee -a "$LOG_FILE" - -log "Building application..." -npm run build 2>&1 | tee -a "$LOG_FILE" - -log "=== Boot update finished (rebuilt successfully) ===" +log "=== Boot update finished (verified/rebuilt) ===" diff --git a/scripts/update-server.sh b/scripts/update-server.sh index ea50031..b31092e 100755 --- a/scripts/update-server.sh +++ b/scripts/update-server.sh @@ -14,8 +14,8 @@ git pull origin main echo -e "${YELLOW}Step 2: Installing dependencies...${NC}" npm install -echo -e "${YELLOW}Step 3: Updating database schema...${NC}" -npx prisma db push +echo -e "${YELLOW}Step 3: Updating database schema (Safe Migrate)...${NC}" +npx prisma migrate deploy echo -e "${YELLOW}Step 4: Regenerating Prisma client...${NC}" npx prisma generate @@ -23,8 +23,10 @@ npx prisma generate echo -e "${YELLOW}Step 5: Building application...${NC}" npm run build -echo -e "${YELLOW}Step 6: Restarting server with PM2...${NC}" -pm2 restart my-weekly-todo || pm2 start npm --name "my-weekly-todo" -- start +echo -e "${YELLOW}Step 6: Restarting server with PM2 (Standalone Mode)...${NC}" +# Delete old process if it exists to ensure fresh config +pm2 delete my-weekly-todo || true +pm2 start .next/standalone/server.js --name "my-weekly-todo" pm2 save echo -e "${GREEN}Update complete! App is running on LXC.${NC}"