
ALTER TABLE public.profiles
  ADD COLUMN IF NOT EXISTS bio TEXT,
  ADD COLUMN IF NOT EXISTS mailing_street TEXT,
  ADD COLUMN IF NOT EXISTS mailing_city TEXT,
  ADD COLUMN IF NOT EXISTS mailing_state TEXT,
  ADD COLUMN IF NOT EXISTS mailing_zip TEXT,
  ADD COLUMN IF NOT EXISTS emergency_contact_name TEXT,
  ADD COLUMN IF NOT EXISTS emergency_contact_phone TEXT,
  ADD COLUMN IF NOT EXISTS preferred_notification_email TEXT,
  ADD COLUMN IF NOT EXISTS preferred_language TEXT DEFAULT 'en',
  ADD COLUMN IF NOT EXISTS notification_preferences JSONB NOT NULL DEFAULT jsonb_build_object(
    'messages_comments', true,
    'financial', true,
    'governance', true,
    'compliance', true
  );

UPDATE public.profiles
SET notification_preferences = jsonb_build_object(
  'messages_comments', true,
  'financial', true,
  'governance', true,
  'compliance', true
)
WHERE notification_preferences IS NULL OR notification_preferences = '{}'::jsonb;
