86 lines
3.0 KiB
PowerShell
86 lines
3.0 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
# Script para aplicar migrations no Supabase remoto
|
|
# Executa a migration de mensagens no projeto do cliente (yuanqfswhberkoevtmfr)
|
|
|
|
Write-Host "==================================" -ForegroundColor Cyan
|
|
Write-Host "MediConnect - Migration Supabase" -ForegroundColor Cyan
|
|
Write-Host "==================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Carregar variáveis do .env
|
|
if (Test-Path .env) {
|
|
Get-Content .env | ForEach-Object {
|
|
if ($_ -match '^([^#][^=]+)=(.+)$') {
|
|
$key = $matches[1].Trim()
|
|
$value = $matches[2].Trim()
|
|
[System.Environment]::SetEnvironmentVariable($key, $value)
|
|
}
|
|
}
|
|
}
|
|
|
|
# Usar o Supabase EXTERNO (do cliente) onde estão os dados
|
|
$SUPABASE_URL = $env:VITE_SUPABASE_URL
|
|
$SUPABASE_KEY = $env:VITE_SUPABASE_ANON_KEY
|
|
|
|
# Extrair project ref da URL (yuanqfswhberkoevtmfr)
|
|
$PROJECT_REF = ""
|
|
if ($SUPABASE_URL -match 'https://([^.]+)\.supabase\.co') {
|
|
$PROJECT_REF = $matches[1]
|
|
}
|
|
|
|
Write-Host "📊 Projeto: $PROJECT_REF" -ForegroundColor Yellow
|
|
Write-Host "🔗 URL: $SUPABASE_URL" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# Verificar se o projeto está linkado
|
|
Write-Host "🔍 Verificando link do projeto..." -ForegroundColor Cyan
|
|
$linkStatus = supabase link --project-ref $PROJECT_REF 2>&1
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "❌ Erro ao linkar projeto. Você precisa estar autenticado:" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "1. Execute: supabase login" -ForegroundColor Yellow
|
|
Write-Host "2. Siga as instruções no browser" -ForegroundColor Yellow
|
|
Write-Host "3. Execute este script novamente" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "✅ Projeto linkado com sucesso!" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Aplicar migrations
|
|
Write-Host "📤 Aplicando migrations..." -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
$migrationFile = "supabase/migrations/20251202000000_create_messaging_system.sql"
|
|
|
|
if (Test-Path $migrationFile) {
|
|
Write-Host "📄 Aplicando: $migrationFile" -ForegroundColor Yellow
|
|
|
|
# Usar supabase db push para aplicar a migration
|
|
supabase db push
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host ""
|
|
Write-Host "✅ Migration aplicada com sucesso!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "🎉 Próximos passos:" -ForegroundColor Cyan
|
|
Write-Host "1. Criar bucket 'message-files' no Storage" -ForegroundColor White
|
|
Write-Host "2. Configurar políticas de storage" -ForegroundColor White
|
|
Write-Host "3. Habilitar Realtime nas tabelas" -ForegroundColor White
|
|
Write-Host ""
|
|
Write-Host "Consulte: supabase/SETUP_STORAGE.md" -ForegroundColor Yellow
|
|
} else {
|
|
Write-Host ""
|
|
Write-Host "❌ Erro ao aplicar migration!" -ForegroundColor Red
|
|
Write-Host "Verifique os logs acima para detalhes" -ForegroundColor Red
|
|
}
|
|
} else {
|
|
Write-Host "❌ Arquivo não encontrado: $migrationFile" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "================================" -ForegroundColor Cyan
|