Files
medical-mall/sql/create_shop_follows.sql

30 lines
1.0 KiB
SQL

-- create_shop_follows.sql
-- Run this in Supabase SQL Editor
CREATE TABLE IF NOT EXISTS public.ml_shop_follows (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
shop_id UUID NOT NULL REFERENCES public.ml_shops(id) ON DELETE CASCADE, -- Assuming ml_shops.id is UUID
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL,
UNIQUE(user_id, shop_id)
);
-- Enable RLS
ALTER TABLE public.ml_shop_follows ENABLE ROW LEVEL SECURITY;
-- Policies
CREATE POLICY "Users can view their own follows"
ON public.ml_shop_follows FOR SELECT
USING (auth.uid() = user_id);
CREATE POLICY "Users can create their own follows"
ON public.ml_shop_follows FOR INSERT
WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can delete their own follows"
ON public.ml_shop_follows FOR DELETE
USING (auth.uid() = user_id);
-- Optional: View count on shops
-- You might want to add follower_count to ml_shops and use triggers to update it.