#!/usr/bin/env bash
set -euo pipefail
APP_ROOT="${APP_ROOT:-/var/www/university-erp}"
TARGET="${1:?usage: rollback.sh /absolute/path/to/previous-release}"
test -d "$TARGET"
ln -sfn "$TARGET" "$APP_ROOT/current.rollback"
mv -Tf "$APP_ROOT/current.rollback" "$APP_ROOT/current"
cd "$APP_ROOT/current"
php artisan queue:restart
curl --fail --silent --show-error --max-time 15 "https://erp.example.edu/ready" >/dev/null
echo "Rolled back application code to $TARGET. No destructive migration rollback was attempted."
