#!/bin/sh
set -e

# Repartir d'un cache propre (évite les providers dev type Pail) puis régénérer.
php artisan optimize:clear || true
php artisan package:discover --ansi

# Optimisations Laravel au démarrage du conteneur
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Migrations (idempotent) — désactivable via RUN_MIGRATIONS=false
if [ "${RUN_MIGRATIONS:-true}" = "true" ]; then
  php artisan migrate --force
fi

exec "$@"
