-- REQ0041-home_discover_event_tab
--
BEGIN;

--
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
CREATE POLICY "public can read profiles" ON public.profiles
  FOR SELECT TO anon
    USING (TRUE);
CREATE POLICY "public can write profiles" ON "public"."profiles" AS PERMISSIVE
  FOR INSERT TO public
    WITH CHECK (TRUE);
CREATE POLICY "public can update profiles" ON "public"."profiles" AS PERMISSIVE
  FOR UPDATE TO public
    USING (TRUE);
CREATE POLICY "public can delete profiles" ON "public"."profiles" AS PERMISSIVE
  FOR DELETE TO public
    USING (TRUE);
COMMIT;
--

-- Set up Realtime
BEGIN;
DROP publication IF EXISTS supabase_realtime;
CREATE publication supabase_realtime;
COMMIT;

ALTER publication supabase_realtime
  ADD TABLE profiles;

-- -- Set up Storage
-- BEGIN;
-- INSERT INTO storage.buckets(id, name)
--   VALUES ('avatars', 'avatars');
-- COMMIT;

-- CREATE POLICY "Avatar images are publicly accessible." ON storage.objects
--   FOR SELECT
--     USING (bucket_id = 'avatars');

-- CREATE POLICY "Anyone can upload an avatar." ON storage.objects
--   FOR INSERT
--     WITH CHECK (bucket_id = 'avatars');

-- CREATE POLICY "Anyone can update an avatar." ON storage.objects
--   FOR UPDATE
--     USING (bucket_id = 'avatars');

-- ---

---