56 lines
2.3 KiB
SQL
56 lines
2.3 KiB
SQL
-- ============================================================================
|
|
-- MIGRATION : Création du bucket Storage "materiel-roulant"
|
|
-- Date : 2026-03-01
|
|
-- Description : Crée le bucket public "materiel-roulant" dans Supabase Storage
|
|
-- et configure les policies RLS.
|
|
--
|
|
-- ⚠️ IMPORTANT — Authentification custom :
|
|
-- Cette application utilise une auth custom (RPC authenticate_user + localStorage)
|
|
-- et NON supabase.auth.signInWithPassword(). Par conséquent auth.uid() est
|
|
-- toujours NULL côté Supabase. Les policies utilisent donc le rôle "anon"
|
|
-- (clé publique anonyme) pour autoriser les opérations Storage depuis le front.
|
|
--
|
|
-- ⚠️ À EXÉCUTER UNE SEULE FOIS dans l'éditeur SQL de votre projet Supabase
|
|
-- (https://supabase.com/dashboard → votre projet → SQL Editor)
|
|
-- ============================================================================
|
|
|
|
-- 1. Créer le bucket s'il n'existe pas encore
|
|
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
|
|
VALUES (
|
|
'materiel-roulant',
|
|
'materiel-roulant',
|
|
true,
|
|
10485760,
|
|
ARRAY['image/jpeg','image/png','image/webp','image/gif','image/svg+xml']
|
|
)
|
|
ON CONFLICT (id) DO NOTHING;
|
|
|
|
-- ============================================================================
|
|
-- 2. Policies RLS sur storage.objects
|
|
-- ============================================================================
|
|
|
|
-- Lecture publique
|
|
DROP POLICY IF EXISTS "materiel-roulant - lecture publique" ON storage.objects;
|
|
CREATE POLICY "materiel-roulant - lecture publique"
|
|
ON storage.objects FOR SELECT
|
|
USING (bucket_id = 'materiel-roulant');
|
|
|
|
-- Upload (anon car auth custom — auth.uid() toujours NULL)
|
|
DROP POLICY IF EXISTS "materiel-roulant - upload authentifié" ON storage.objects;
|
|
CREATE POLICY "materiel-roulant - upload authentifié"
|
|
ON storage.objects FOR INSERT
|
|
WITH CHECK (bucket_id = 'materiel-roulant');
|
|
|
|
-- Mise à jour
|
|
DROP POLICY IF EXISTS "materiel-roulant - update authentifié" ON storage.objects;
|
|
CREATE POLICY "materiel-roulant - update authentifié"
|
|
ON storage.objects FOR UPDATE
|
|
USING (bucket_id = 'materiel-roulant');
|
|
|
|
-- Suppression
|
|
DROP POLICY IF EXISTS "materiel-roulant - delete authentifié" ON storage.objects;
|
|
CREATE POLICY "materiel-roulant - delete authentifié"
|
|
ON storage.objects FOR DELETE
|
|
USING (bucket_id = 'materiel-roulant');
|
|
|