diff --git a/scripts/deploy/scripts/run_migrations.sh b/scripts/deploy/scripts/run_migrations.sh index 775e2b75..9d4933de 100755 --- a/scripts/deploy/scripts/run_migrations.sh +++ b/scripts/deploy/scripts/run_migrations.sh @@ -29,10 +29,14 @@ else SSH_PORT=13308 fi -# Create SSH tunnel -echo "Creating SSH tunnel to $TARGET database on localhost:$SSH_PORT..." -ssh -f -N -L $SSH_PORT:localhost:$DB_PORT cmc -sleep 2 +# Create SSH tunnel if not already running +if ! lsof -ti:$SSH_PORT > /dev/null 2>&1; then + echo "Creating SSH tunnel to $TARGET database on localhost:$SSH_PORT..." + ssh -f -N -L $SSH_PORT:localhost:$DB_PORT cmc + sleep 2 +else + echo "SSH tunnel already exists on localhost:$SSH_PORT, reusing it..." +fi # Load goose.env and override the port GOOSE_ENV_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../go" && pwd)/goose.env"