#!/bin/bash
# =============================================================================
# Executa todos os seeds na ordem correta
# =============================================================================
# Uso: bash run_all_seeds.sh
#
# Pré-requisitos:
#   - Container supabase_db_agenciapsi-primesakai rodando
#   - Schema já aplicado (schema/00_full/schema.sql)
# =============================================================================

CONTAINER="supabase_db_agenciapsi-primesakai"
DIR="$(cd "$(dirname "$0")" && pwd)"

set -e

echo "=== Aplicando seeds — Usuários ==="

for seed in \
  seed_001_fixed.sql \
  seed_002.sql \
  seed_003.sql
do
  echo ""
  echo ">>> $seed"
  docker exec -i "$CONTAINER" psql -U postgres -d postgres < "$DIR/$seed"
  echo "<<< OK"
done

echo ""
echo "=== Aplicando seeds — Sistema (planos, features, subscriptions) ==="

for seed in \
  seed_010_plans.sql \
  seed_011_features.sql \
  seed_012_plan_features.sql \
  seed_013_subscriptions.sql \
  seed_014_global_data.sql
do
  echo ""
  echo ">>> $seed"
  docker exec -i "$CONTAINER" psql -U postgres -d postgres < "$DIR/$seed"
  echo "<<< OK"
done

echo ""
echo "=== Todos os seeds aplicados com sucesso ==="
