feat: Payload CMS robustness - auto-detect migrations, deep health check, improved error messages

- cms-sync.sh: auto-detect migrations from src/migrations/*.ts (no manual list)
- cms-sync.sh: pre-flight container checks with actionable error messages
- api/health/cms: deep health check that queries all Payload collections
- deploy.yml: auto-detect migrations in sanitization step
- deploy.yml: CMS deep health smoke test in post-deploy
This commit is contained in:
2026-02-27 02:36:59 +01:00
parent 0be885428d
commit cadb104917
3 changed files with 116 additions and 26 deletions

View File

@@ -53,13 +53,17 @@ TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
REMOTE_DB_USER=""
REMOTE_DB_NAME=""
# Migration names to insert after restore (keeps Payload from prompting)
MIGRATIONS=(
"20260223_195005_products_collection:1"
"20260223_195151_remove_sku_unique:2"
"20260225_003500_add_pages_collection:3"
"20260225_175000_native_localization:4"
)
# Auto-detect migrations from src/migrations/*.ts (no manual maintenance needed)
MIGRATIONS=()
BATCH=1
for migration_file in $(ls src/migrations/*.ts 2>/dev/null | sort); do
name=$(basename "$migration_file" .ts)
MIGRATIONS+=("$name:$BATCH")
((BATCH++))
done
if [ ${#MIGRATIONS[@]} -eq 0 ]; then
echo "⚠️ No migration files found in src/migrations/"
fi
# ── Resolve target environment ─────────────────────────────────────────────
resolve_target() {
@@ -159,6 +163,29 @@ backup_remote_db() {
REMOTE_BACKUP_FILE="$file"
}
# ── Pre-flight: Verify remote containers exist ─────────────────────────────
check_remote_containers() {
echo "🔍 Checking $TARGET containers..."
local missing=0
if ! ssh "$SSH_HOST" "docker ps -q -f name=$REMOTE_DB_CONTAINER" | grep -q .; then
echo "❌ Database container '$REMOTE_DB_CONTAINER' not found on $SSH_HOST"
echo " → Deploy $TARGET first: git push to trigger pipeline, or run:"
echo " ssh $SSH_HOST \"cd $REMOTE_SITE_DIR && docker compose -p $REMOTE_PROJECT --env-file .env.\$TARGET up -d\""
missing=1
fi
if ! ssh "$SSH_HOST" "docker ps -q -f name=$REMOTE_APP_CONTAINER" | grep -q .; then
echo "❌ App container '$REMOTE_APP_CONTAINER' not found on $SSH_HOST"
missing=1
fi
if [ $missing -eq 1 ]; then
echo ""
echo "💡 The $TARGET environment hasn't been deployed yet."
echo " Push to the '$TARGET' branch or run the pipeline first."
exit 1
fi
echo "✅ All $TARGET containers running."
}
# ── PUSH: local → remote ──────────────────────────────────────────────────
do_push() {
echo ""
@@ -172,8 +199,9 @@ do_push() {
echo ""
[[ ! $REPLY =~ ^[Yy]$ ]] && { echo "Cancelled."; exit 0; }
# 0. Ensure local DB is running
# 0. Ensure local DB is running & remote containers exist
ensure_local_db
check_remote_containers
# 1. Safety backup of remote
backup_remote_db
@@ -227,8 +255,9 @@ do_pull() {
echo ""
[[ ! $REPLY =~ ^[Yy]$ ]] && { echo "Cancelled."; exit 0; }
# 0. Ensure local DB is running
# 0. Ensure local DB is running & remote containers exist
ensure_local_db
check_remote_containers
# 1. Safety backup of local
backup_local_db