38980-vm/app-9w9pd00g5j41/supabase/migrations/00006_allow_anonymous_trips.sql
2026-03-04 18:25:09 +00:00

59 lines
2.0 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- user_id'yi nullable yap
ALTER TABLE trips ALTER COLUMN user_id DROP NOT NULL;
-- Anonim kullanıcılar için RLS politikaları
DROP POLICY IF EXISTS "Kullanıcılar kendi seyahatlerini oluşturabilir" ON trips;
DROP POLICY IF EXISTS "Kullanıcılar kendi seyahatlerini görebilir" ON trips;
DROP POLICY IF EXISTS "Kullanıcılar kendi seyahatlerini güncelleyebilir" ON trips;
DROP POLICY IF EXISTS "Kullanıcılar kendi seyahatlerini silebilir" ON trips;
-- Yeni politikalar
CREATE POLICY "Herkes seyahat oluşturabilir"
ON trips FOR INSERT
WITH CHECK (true);
CREATE POLICY "Herkes public seyahatleri görebilir"
ON trips FOR SELECT
USING (is_public = true OR auth.uid() = user_id OR user_id IS NULL);
CREATE POLICY "Kullanıcılar kendi seyahatlerini güncelleyebilir"
ON trips FOR UPDATE
USING (auth.uid() = user_id OR user_id IS NULL);
CREATE POLICY "Kullanıcılar kendi seyahatlerini silebilir"
ON trips FOR DELETE
USING (auth.uid() = user_id OR user_id IS NULL);
-- Trip days için anonim erişim
DROP POLICY IF EXISTS "Kullanıcılar kendi seyahat günlerini yönetebilir" ON trip_days;
CREATE POLICY "Herkes seyahat günlerini yönetebilir"
ON trip_days FOR ALL
USING (
EXISTS (
SELECT 1 FROM trips
WHERE trips.id = trip_days.trip_id
AND (trips.user_id = auth.uid() OR trips.user_id IS NULL OR trips.is_public = true)
)
);
-- Trip places için anonim erişim
DROP POLICY IF EXISTS "Kullanıcılar kendi seyahat yerlerini yönetebilir" ON trip_places;
CREATE POLICY "Herkes seyahat yerlerini yönetebilir"
ON trip_places FOR ALL
USING (
EXISTS (
SELECT 1 FROM trip_days
JOIN trips ON trips.id = trip_days.trip_id
WHERE trip_days.id = trip_places.trip_day_id
AND (trips.user_id = auth.uid() OR trips.user_id IS NULL OR trips.is_public = true)
)
);
-- Places tablosu için anonim okuma
DROP POLICY IF EXISTS "Herkes yerleri görebilir" ON places;
CREATE POLICY "Herkes yerleri görebilir"
ON places FOR SELECT
USING (true);