From 06a9a04199efa330caccc29fdf9e79278a8cb475 Mon Sep 17 00:00:00 2001 From: DanielS Date: Fri, 1 May 2026 01:04:02 +0200 Subject: [PATCH] feat: add profiles table and RLS policies for user customer data --- .../20260430230348_add_profiles_table.sql | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 shop/supabase/migrations/20260430230348_add_profiles_table.sql 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');