riseup-squad18/setup-storage.ps1
2025-12-06 19:13:27 -03:00

88 lines
3.1 KiB
PowerShell
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env pwsh
# Script para configurar Storage no Supabase
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Configurando Storage para Mensagens" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "📦 PRÓXIMOS PASSOS MANUAIS:" -ForegroundColor Yellow
Write-Host ""
Write-Host "1⃣ Criar Bucket de Storage:" -ForegroundColor White
Write-Host " • Acesse: https://supabase.com/dashboard/project/etblfypcxxtvvuqjkrgd/storage/buckets" -ForegroundColor Gray
Write-Host " • Clique em 'New bucket'" -ForegroundColor Gray
Write-Host " • Nome: message-files" -ForegroundColor Green
Write-Host " • Marque: Public bucket ✓" -ForegroundColor Gray
Write-Host " • Clique em 'Create bucket'" -ForegroundColor Gray
Write-Host ""
Write-Host "2⃣ Configurar Políticas de Storage:" -ForegroundColor White
Write-Host " • Acesse: https://supabase.com/dashboard/project/etblfypcxxtvvuqjkrgd/storage/policies" -ForegroundColor Gray
Write-Host " • Selecione o bucket 'message-files'" -ForegroundColor Gray
Write-Host " • Adicione as seguintes políticas:" -ForegroundColor Gray
Write-Host ""
Write-Host " Execute este SQL no SQL Editor:" -ForegroundColor Yellow
Write-Host ""
Write-Host @'
-- Política 1: Upload (INSERT)
CREATE POLICY "Users can upload files"
ON storage.objects FOR INSERT
TO authenticated
WITH CHECK (
bucket_id = 'message-files' AND
auth.uid()::text = (storage.foldername(name))[1]
);
-- Política 2: Download (SELECT)
CREATE POLICY "Anyone can download files"
ON storage.objects FOR SELECT
TO public
USING (bucket_id = 'message-files');
-- Política 3: Update
CREATE POLICY "Users can update their own files"
ON storage.objects FOR UPDATE
TO authenticated
USING (
bucket_id = 'message-files' AND
auth.uid()::text = (storage.foldername(name))[1]
);
-- Política 4: Delete
CREATE POLICY "Users can delete their own files"
ON storage.objects FOR DELETE
TO authenticated
USING (
bucket_id = 'message-files' AND
auth.uid()::text = (storage.foldername(name))[1]
);
'@ -ForegroundColor DarkGray
Write-Host ""
Write-Host "3⃣ Configurar Limites (Opcional):" -ForegroundColor White
Write-Host " • Tamanho máximo: 10MB" -ForegroundColor Gray
Write-Host " • Tipos permitidos: PDF, imagens, documentos" -ForegroundColor Gray
Write-Host ""
$limitSql = @"
-- Executar no SQL Editor
UPDATE storage.buckets
SET file_size_limit = 10485760,
allowed_mime_types = ARRAY[
'image/jpeg', 'image/png', 'image/gif',
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'text/plain'
]::text[]
WHERE id = 'message-files';
"@
Write-Host $limitSql -ForegroundColor DarkGray
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "✅ Migration aplicada com sucesso!" -ForegroundColor Green
Write-Host "📋 Complete os passos acima no Dashboard" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Cyan