#!/bin/bash

# Deploy de mudanças de orçamentos com subcategorias

SERVER="root@213.165.93.60"
PASS="Master9354"

echo "📦 Enviando arquivos..."

# Enviar migration
sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  /workspaces/webmoney/backend/database/migrations/2025_12_16_211102_add_subcategory_to_budgets_table.php \
  $SERVER:/var/www/webmoney/backend/database/migrations/

# Enviar Model
sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  /workspaces/webmoney/backend/app/Models/Budget.php \
  $SERVER:/var/www/webmoney/backend/app/Models/

# Enviar Controller
sshpass -p "$PASS" scp -o StrictHostKeyChecking=no \
  /workspaces/webmoney/backend/app/Http/Controllers/Api/BudgetController.php \
  $SERVER:/var/www/webmoney/backend/app/Http/Controllers/Api/

echo "✅ Arquivos enviados"
echo ""

echo "🔄 Executando migration..."
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $SERVER "cd /var/www/webmoney/backend && php artisan migrate --force"

echo ""
echo "🎯 Limpando cache..."
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $SERVER "cd /var/www/webmoney/backend && php artisan config:clear && php artisan cache:clear && php artisan route:clear"

echo ""
echo "✅ Deploy do backend concluído!"
