mirror of
https://github.com/FranP-code/inbox-negotiator.git
synced 2025-10-13 00:42:26 +00:00
Add personal data management to user configuration and onboarding
This commit is contained in:
38
supabase/migrations/20250607007000_add_personal_data.sql
Normal file
38
supabase/migrations/20250607007000_add_personal_data.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
-- Add personal data to the users table for debt negotiation letters
|
||||
-- This will store the user's personal information needed for generating formal negotiation letters
|
||||
|
||||
-- Add personal data columns to the public.users table
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS full_name TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS address_line_1 TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS address_line_2 TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS city TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS state TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS zip_code TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS phone_number TEXT;
|
||||
ALTER TABLE public.users ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ DEFAULT NOW();
|
||||
|
||||
-- Create index for performance
|
||||
CREATE INDEX IF NOT EXISTS idx_users_updated_at ON public.users(updated_at);
|
||||
|
||||
-- Update RLS policy to allow users to update their own data
|
||||
CREATE POLICY "Users can update own profile" ON public.users
|
||||
FOR UPDATE USING (auth.uid() = id);
|
||||
|
||||
-- Grant UPDATE permission to authenticated users
|
||||
GRANT UPDATE ON public.users TO authenticated;
|
||||
|
||||
-- Create function to update updated_at timestamp
|
||||
CREATE OR REPLACE FUNCTION update_users_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
|
||||
-- Create trigger for updated_at
|
||||
DROP TRIGGER IF EXISTS update_users_updated_at ON public.users;
|
||||
CREATE TRIGGER update_users_updated_at
|
||||
BEFORE UPDATE ON public.users
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_users_updated_at_column();
|
||||
Reference in New Issue
Block a user