Fix unit display errors

This commit is contained in:
gpt-engineer-app[bot]
2025-09-28 22:51:44 +00:00
parent 8f13796567
commit a6e9d77bda
5 changed files with 114 additions and 4 deletions

View File

@@ -0,0 +1,26 @@
-- Update existing user_preferences records to include unit preferences if they don't have them
UPDATE public.user_preferences
SET unit_preferences = '{"measurement_system": "metric", "temperature": "celsius", "auto_detect": true}'::jsonb
WHERE unit_preferences IS NULL OR unit_preferences = '{}'::jsonb;
-- Update the initialize_user_preferences function to include unit preferences
CREATE OR REPLACE FUNCTION public.initialize_user_preferences()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = 'public'
AS $function$
BEGIN
INSERT INTO public.user_preferences (
user_id,
unit_preferences
)
VALUES (
NEW.user_id,
'{"measurement_system": "metric", "temperature": "celsius", "auto_detect": true}'::jsonb
)
ON CONFLICT (user_id) DO UPDATE SET
unit_preferences = COALESCE(public.user_preferences.unit_preferences, '{"measurement_system": "metric", "temperature": "celsius", "auto_detect": true}'::jsonb);
RETURN NEW;
END;
$function$;