diff --git a/shop/supabase/migrations/20260430230348_add_profiles_table.sql b/shop/supabase/migrations/20260430230348_add_profiles_table.sql new file mode 100644 index 0000000..ee6a560 --- /dev/null +++ b/shop/supabase/migrations/20260430230348_add_profiles_table.sql @@ -0,0 +1,21 @@ +-- Profiles Table +CREATE TABLE IF NOT EXISTS public.profiles ( + id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE, + first_name TEXT, + last_name TEXT, + company_name TEXT, + vat_id TEXT, + address TEXT, + city TEXT, + zip_code TEXT, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL +); + +-- Enable RLS +ALTER TABLE public.profiles ENABLE ROW LEVEL SECURITY; + +-- Policies +CREATE POLICY "Users can view their own profile" ON public.profiles FOR SELECT USING (auth.uid() = id); +CREATE POLICY "Users can update their own profile" ON public.profiles FOR UPDATE USING (auth.uid() = id); +CREATE POLICY "Users can insert their own profile" ON public.profiles FOR INSERT WITH CHECK (auth.uid() = id); +CREATE POLICY "Admins can view all profiles" ON public.profiles FOR SELECT USING (auth.role() = 'authenticated');