#!/bin/bash set -euo pipefail : "${SUPERADMIN_PASSWORD:?请设置环境变量 SUPERADMIN_PASSWORD}" ENV_FILE=/opt/ai-fresh-delivery/server/.env NEW_URL='postgresql://hermes:Hermes_2026_DB@1.13.62.2:20538/ai_fresh_delivery' cp "$ENV_FILE" "${ENV_FILE}.bak.$(date +%Y%m%d%H%M%S)" sed -i "s|^DATABASE_URL=.*|DATABASE_URL=$NEW_URL|" "$ENV_FILE" echo "=== updated DATABASE_URL ===" grep '^DATABASE_URL=' "$ENV_FILE" echo echo "=== DB ping ===" export DATABASE_URL="$NEW_URL" cd /opt/ai-fresh-delivery/server node -e "const {Pool}=require('pg');(async()=>{const p=new Pool({connectionString:process.env.DATABASE_URL,connectionTimeoutMillis:15000});const r=await p.query('SELECT current_database() db, COUNT(*)::int orders FROM orders');console.log(r.rows[0]);await p.end();})();" echo echo "=== restart api ===" sudo systemctl restart ai-fresh-api sleep 3 systemctl is-active ai-fresh-api echo echo "=== health ===" curl -sS -m 10 http://127.0.0.1:3001/api/health echo echo echo "=== login test ===" curl -sS -m 15 -X POST http://127.0.0.1:3001/api/auth/unified-login \ -H 'Content-Type: application/json' \ --data-raw "$(printf '{"username":"%s","password":"%s"}' "superadmin" "$SUPERADMIN_PASSWORD")" echo