#!/bin/bash
echo "Running essential pre-start tasks..."

# Clear all caches first
echo "Clearing caches..."
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

# Run migrations
echo "Running migrations..."
php artisan migrate --force

# Check if migrations completed successfully
if [ $? -eq 0 ]; then
    echo "Migrations completed successfully."
    
    # Run seeders only if migrations succeeded
    echo "Running seeders..."
    php artisan db:seed --force
else
    echo "Migration failed. Skipping seeders."
    exit 1
fi

echo "Pre-start tasks finished."