Files
avbeat-com/supabase/migrations/20260321065000_post_images_storage.sql
2026-05-07 16:39:17 +00:00

51 lines
1.5 KiB
SQL

-- ============================================================
-- Migration: post_images_storage
-- Timestamp: 20260321065000
-- Creates storage bucket for WordPress imported post images
-- ============================================================
-- 1. Create the storage bucket for post images
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
VALUES (
'post-images',
'post-images',
true,
10485760, -- 10MB limit
ARRAY['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml']
)
ON CONFLICT (id) DO NOTHING;
-- 2. RLS Policies for storage.objects (post-images bucket)
-- Public read access
DROP POLICY IF EXISTS "post_images_public_read" ON storage.objects;
CREATE POLICY "post_images_public_read"
ON storage.objects
FOR SELECT
TO public
USING (bucket_id = 'post-images');
-- Authenticated users can upload
DROP POLICY IF EXISTS "post_images_authenticated_insert" ON storage.objects;
CREATE POLICY "post_images_authenticated_insert"
ON storage.objects
FOR INSERT
TO authenticated
WITH CHECK (bucket_id = 'post-images');
-- Authenticated users can update
DROP POLICY IF EXISTS "post_images_authenticated_update" ON storage.objects;
CREATE POLICY "post_images_authenticated_update"
ON storage.objects
FOR UPDATE
TO authenticated
USING (bucket_id = 'post-images');
-- Authenticated users can delete
DROP POLICY IF EXISTS "post_images_authenticated_delete" ON storage.objects;
CREATE POLICY "post_images_authenticated_delete"
ON storage.objects
FOR DELETE
TO authenticated
USING (bucket_id = 'post-images');