-- Backfill missing privacy settings fields for existing users UPDATE user_preferences SET privacy_settings = privacy_settings || jsonb_build_object( 'show_avatar', COALESCE((privacy_settings->>'show_avatar')::boolean, true), 'show_bio', COALESCE((privacy_settings->>'show_bio')::boolean, true), 'show_activity_stats', COALESCE((privacy_settings->>'show_activity_stats')::boolean, true), 'show_home_park', COALESCE((privacy_settings->>'show_home_park')::boolean, false) ) WHERE privacy_settings IS NOT NULL AND ( privacy_settings->>'show_avatar' IS NULL OR privacy_settings->>'show_bio' IS NULL OR privacy_settings->>'show_activity_stats' IS NULL OR privacy_settings->>'show_home_park' IS NULL );