#!/bin/bash
# Déploiement recette new.vulcanaffutage.com — à lancer depuis ~/new-v2
# Usage : ./deploy.sh            (pull + install + migrations)
#         ./deploy.sh --fixtures (idem + rechargement des fixtures = PURGE la base)
set -e
cd "$(dirname "$0")"
PHP=/usr/local/php8.4/bin/php
COMPOSER=$HOME/composer

echo '==> git pull'
git pull --ff-only

echo '==> composer install'
COMPOSER_MEMORY_LIMIT=-1 $PHP $COMPOSER install --no-interaction --optimize-autoloader

echo '==> migrations'
$PHP bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration

if [ "$1" = '--fixtures' ]; then
  echo '==> fixtures (PURGE de la base vulcanskylianv2)'
  $PHP bin/console doctrine:fixtures:load --no-interaction
fi

echo '==> cache'
$PHP bin/console cache:clear --no-interaction
$PHP bin/console cache:warmup --no-interaction

echo '==> OK — https://new.vulcanaffutage.com'
