From 8de74029722295e0de078c8f509f01c7dd33e3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 9 Feb 2024 14:04:21 +0000 Subject: [PATCH] feat: Add migration for analytics_logs.metadata --- .../down.sql | 23 +++++++++++++++++++ .../up.sql | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/down.sql create mode 100644 hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/up.sql diff --git a/hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/down.sql b/hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/down.sql new file mode 100644 index 0000000000..f48312068d --- /dev/null +++ b/hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/down.sql @@ -0,0 +1,23 @@ +UPDATE public.analytics_logs +SET metadata = jsonb_set( + metadata, + '{back,type}', + CASE + WHEN metadata->'back'->>'type' = 'Question' THEN '"Statement"' + WHEN metadata->'back'->>'type' = 'Answer' THEN '"Response"' + ELSE metadata->'back'->>'type' + END::jsonb +) +WHERE metadata->'back'->>'type' IN ('Question', 'Answer'); + +UPDATE public.analytics_logs +SET metadata = jsonb_set( + metadata, + '{change,type}', + CASE + WHEN metadata->'change'->>'type' = 'Question' THEN '"Statement"' + WHEN metadata->'change'->>'type' = 'Answer' THEN '"Response"' + ELSE metadata->'change'->>'type' + END::jsonb +) +WHERE metadata->'change'->>'type' IN ('Question', 'Answer'); diff --git a/hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/up.sql b/hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/up.sql new file mode 100644 index 0000000000..69b17a1efd --- /dev/null +++ b/hasura.planx.uk/migrations/1707487370419_update_metadata_component_types/up.sql @@ -0,0 +1,23 @@ +UPDATE public.analytics_logs +SET metadata = jsonb_set( + metadata, + '{back,type}', + CASE + WHEN metadata->'back'->>'type' = 'Statement' THEN '"Question"' + WHEN metadata->'back'->>'type' = 'Response' THEN '"Answer"' + ELSE metadata->'back'->>'type' + END::jsonb +) +WHERE metadata->'back'->>'type' IN ('Statement', 'Response'); + +UPDATE public.analytics_logs +SET metadata = jsonb_set( + metadata, + '{change,type}', + CASE + WHEN metadata->'change'->>'type' = 'Statement' THEN '"Question"' + WHEN metadata->'change'->>'type' = 'Response' THEN '"Answer"' + ELSE metadata->'change'->>'type' + END::jsonb +) +WHERE metadata->'change'->>'type' IN ('Statement', 'Response');