Spaces:
Sleeping

fx-craft / supabase_project_2_setup.sql
felix-fx's picture
Initial setup for fx-craft website
9694b21 verified
Raw History Blame Contribute Delete
1.75 kB
-- 1. تفعيل Row Level Security على جدول profiles
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
-- 2. سياسة السماح للجميع بقراءة الملفات الشخصية (لأغراض العرض)
CREATE POLICY "Profiles are viewable by everyone"
ON profiles FOR SELECT
USING (true);
-- 3. سياسة السماح للمستخدم بتحديث ملفه الشخصي فقط بناءً على JWT
-- ملاحظة: نفترض أن user_id في الجدول يطابق auth.uid() من JWT
CREATE POLICY "Users can update their own profile"
ON profiles FOR UPDATE
USING (auth.uid()::text = user_id::text);
-- 4. سياسة السماح للمستخدم بإدراج ملفه الشخصي عند التسجيل
CREATE POLICY "Users can insert their own profile"
ON profiles FOR INSERT
WITH CHECK (auth.uid()::text = user_id::text);
-- 5. تفعيل RLS لجدول الإضافات (mods) إذا كان موجوداً
DO $$
BEGIN
IF EXISTS (SELECT FROM pg_tables WHERE tablename = 'mods') THEN
ALTER TABLE mods ENABLE ROW LEVEL SECURITY;
-- السماح للجميع بمشاهدة الإضافات
CREATE POLICY "Mods are viewable by everyone" ON mods FOR SELECT USING (true);
-- السماح للمطورين فقط بإضافة/تعديل إضافاتهم
CREATE POLICY "Developers can insert their own mods" ON mods FOR INSERT WITH CHECK (auth.uid()::text = developer_id::text);
CREATE POLICY "Developers can update their own mods" ON mods FOR UPDATE USING (auth.uid()::text = developer_id::text);
CREATE POLICY "Developers can delete their own mods" ON mods FOR DELETE USING (auth.uid()::text = developer_id::text);
END IF;
END $$;