Merge pull request #990 from buster-so/wells-bus-1835-still-using-metric-vs-metricfile-on-the-reasoning-page

migration to update messages.reasoning column
This commit is contained in:
wellsbunk5 2025-09-18 09:37:15 -06:00 committed by GitHub
commit a8359373c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7698 additions and 0 deletions

View File

@ -0,0 +1,76 @@
-- Custom SQL migration file, put your code below! --
-- Migration to update file_type values in the reasoning JSONB column
-- This migration updates the following mappings in the reasoning column:
-- 'metric' -> 'metric_file'
-- 'dashboard' -> 'dashboard_file'
-- 'report' -> 'report_file'
DO $$
BEGIN
RAISE NOTICE 'Updating messages.reasoning JSONB file_type values...';
UPDATE public.messages
SET reasoning = (
SELECT jsonb_agg(
CASE
WHEN reasoning_item ? 'files' THEN
-- Handle the files object structure
jsonb_set(
reasoning_item,
'{files}',
(
SELECT jsonb_object_agg(
file_key,
CASE
WHEN file_value->>'file_type' = 'metric' THEN
jsonb_set(file_value, '{file_type}', '"metric_file"')
WHEN file_value->>'file_type' = 'dashboard' THEN
jsonb_set(file_value, '{file_type}', '"dashboard_file"')
WHEN file_value->>'file_type' = 'report' THEN
jsonb_set(file_value, '{file_type}', '"report_file"')
ELSE file_value
END
)
FROM jsonb_each(reasoning_item->'files') AS files_obj(file_key, file_value)
)
)
WHEN reasoning_item ? 'file_type' THEN
-- Handle direct file_type field
CASE
WHEN reasoning_item->>'file_type' = 'metric' THEN
jsonb_set(reasoning_item, '{file_type}', '"metric_file"')
WHEN reasoning_item->>'file_type' = 'dashboard' THEN
jsonb_set(reasoning_item, '{file_type}', '"dashboard_file"')
WHEN reasoning_item->>'file_type' = 'report' THEN
jsonb_set(reasoning_item, '{file_type}', '"report_file"')
ELSE reasoning_item
END
ELSE reasoning_item
END
)
FROM jsonb_array_elements(reasoning) AS reasoning_item
)
WHERE jsonb_typeof(reasoning) = 'array'
AND EXISTS (
SELECT 1
FROM jsonb_array_elements(reasoning) AS reasoning_item
WHERE (
-- Check for file_type in files object
reasoning_item ? 'files'
AND EXISTS (
SELECT 1
FROM jsonb_each(reasoning_item->'files') AS files_obj(file_key, file_value)
WHERE file_value->>'file_type' IN ('metric', 'dashboard', 'report')
)
)
OR (
-- Check for direct file_type field
reasoning_item ? 'file_type'
AND reasoning_item->>'file_type' IN ('metric', 'dashboard', 'report')
)
)
AND deleted_at IS NULL;
RAISE NOTICE 'Reasoning column file_type migration completed successfully!';
END $$;

File diff suppressed because it is too large Load Diff

View File

@ -729,6 +729,13 @@
"when": 1758141670999,
"tag": "0104_organic_zuras",
"breakpoints": true
},
{
"idx": 105,
"version": "7",
"when": 1758208025186,
"tag": "0105_flimsy_drax",
"breakpoints": true
}
]
}