#!/bin/bash set -euo pipefail # ============================================================================== # SAQEL PLATFORM - DEPLOY & GIT SYNCHRONIZATION SCRIPT # ============================================================================== if [ -n "${1:-}" ]; then COMMIT_MSG="$1" else COMMIT_MSG="Update Saqel Platform: $(date +'%Y-%m-%d %H:%M:%S')" fi echo "πŸ“¦ Staging all files..." git add . echo "πŸ“ Committing: $COMMIT_MSG" if git diff --cached --quiet; then echo "ℹ️ No staged changes to commit." else git commit -m "$COMMIT_MSG" fi echo "πŸš€ Pushing to origin..." git push origin main echo "βœ… Done! On the production server run:" echo " git pull" echo " (and if websocket server changed: php backend/websocket/server.php restart -d)" # Optional remote continuation. Never guesses a host and never applies DDL # unless the operator explicitly opts in after seeing status and dry-run. if [ -n "${DEPLOY_SSH_TARGET:-}" ]; then APP_DIR="${DEPLOY_APP_DIR:-/var/www/saqel}" echo "πŸ” Updating remote work tree: ${DEPLOY_SSH_TARGET}:${APP_DIR}" ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && git pull --ff-only origin main" echo "πŸ”Ž Remote migration status" ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && php backend/scripts/run_migrations.php --status" echo "πŸ§ͺ Remote migration dry-run" ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && php backend/scripts/run_migrations.php --dry-run" if [ "${DEPLOY_RUN_MIGRATIONS:-0}" = "1" ]; then echo "🚧 Applying remote migrations by explicit opt-in" ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && php backend/scripts/run_migrations.php" else echo "⏸️ Migrations were not applied. Set DEPLOY_RUN_MIGRATIONS=1 after reviewing dry-run." fi fi