Files
orangecat/scripts/db/fix-avatar-upload-rls.sql
Georgy ButaevandClaude Opus 4.8 054204e943 chore(infra): retire managed Supabase cloud; Hetzner self-host is SSOT
The managed Supabase Cloud project (ohkueislstxomdjavyhs) is retired; the
self-hosted instance at supabase.orangecat.ch on the Hetzner box is the single
source of truth. Repoint the image host + setup scripts, rewrite the agent/dev
guidance to use the self-host directly (not the Supabase MCP, which only reaches
the retired cloud), update active docs, exit retired cloud-Management-API
scripts behind a RETIRED guard, env-ify direct-connect scripts, gitignore
.env-backups, and add a founder-run DECOMMISSION-CLOUD runbook. No live code
path references the managed project anymore.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 09:26:58 +02:00

71 lines
2.5 KiB
SQL

-- ============================================================================
-- FIX AVATAR UPLOAD RLS POLICY
-- Run this via psql "$POSTGRES_URL" on the self-hosted DB (supabase.orangecat.ch) - managed cloud retired
-- ============================================================================
-- Enable RLS on storage.objects if not already enabled
ALTER TABLE storage.objects ENABLE ROW LEVEL SECURITY;
-- Drop existing policies if they exist (to avoid conflicts)
DROP POLICY IF EXISTS "Users can upload their own profile images" ON storage.objects;
DROP POLICY IF EXISTS "Users can update their own profile images" ON storage.objects;
DROP POLICY IF EXISTS "Users can delete their own profile images" ON storage.objects;
DROP POLICY IF EXISTS "Public profiles bucket is publicly readable" ON storage.objects;
DROP POLICY IF EXISTS "Users can upload their own avatars" ON storage.objects;
DROP POLICY IF EXISTS "Users can update their own avatars" ON storage.objects;
DROP POLICY IF EXISTS "Users can delete their own avatars" ON storage.objects;
DROP POLICY IF EXISTS "Public avatars bucket is publicly readable" ON storage.objects;
-- Create avatars bucket if it doesn't exist
INSERT INTO storage.buckets (id, name, public)
VALUES ('avatars', 'avatars', true)
ON CONFLICT (id) DO UPDATE
SET public = true;
-- Policy 1: Users can INSERT (upload) their own avatars
-- File paths are: {userId}/avatar_{timestamp}.{ext}
CREATE POLICY "Users can upload their own avatars"
ON storage.objects
FOR INSERT
TO authenticated
WITH CHECK (
bucket_id = 'avatars' AND
(storage.foldername(name))[1] = auth.uid()::text
);
-- Policy 2: Users can UPDATE their own avatars
CREATE POLICY "Users can update their own avatars"
ON storage.objects
FOR UPDATE
TO authenticated
USING (
bucket_id = 'avatars' AND
(storage.foldername(name))[1] = auth.uid()::text
)
WITH CHECK (
bucket_id = 'avatars' AND
(storage.foldername(name))[1] = auth.uid()::text
);
-- Policy 3: Users can DELETE their own avatars
CREATE POLICY "Users can delete their own avatars"
ON storage.objects
FOR DELETE
TO authenticated
USING (
bucket_id = 'avatars' AND
(storage.foldername(name))[1] = auth.uid()::text
);
-- Policy 4: Public read access to all avatars
CREATE POLICY "Public avatars bucket is publicly readable"
ON storage.objects
FOR SELECT
TO public
USING (bucket_id = 'avatars');
-- Verify the policies were created
SELECT schemaname, tablename, policyname, permissive, roles, cmd, qual
FROM pg_policies
WHERE tablename = 'objects' AND policyname LIKE '%avatar%';