From 11af05876a6b43ba56a22a14809eec9db4d1b3cb Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Tue, 14 May 2024 14:23:23 +0200 Subject: [PATCH] create submission_services_log view --- hasura.planx.uk/metadata/tables.yaml | 3 ++ .../down.sql | 1 + .../up.sql | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 hasura.planx.uk/migrations/1715689232003_create view submission services log /down.sql create mode 100644 hasura.planx.uk/migrations/1715689232003_create view submission services log /up.sql diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index 5eaac0e3f0..1227515ef1 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -1360,6 +1360,9 @@ - locked_at: _is_null: true check: null +- table: + name: submission_services_log + schema: public - table: name: submission_services_summary schema: public diff --git a/hasura.planx.uk/migrations/1715689232003_create view submission services log /down.sql b/hasura.planx.uk/migrations/1715689232003_create view submission services log /down.sql new file mode 100644 index 0000000000..753d1262be --- /dev/null +++ b/hasura.planx.uk/migrations/1715689232003_create view submission services log /down.sql @@ -0,0 +1 @@ +drop view if exists public.submission_services_log cascade; diff --git a/hasura.planx.uk/migrations/1715689232003_create view submission services log /up.sql b/hasura.planx.uk/migrations/1715689232003_create view submission services log /up.sql new file mode 100644 index 0000000000..fe0efbb9db --- /dev/null +++ b/hasura.planx.uk/migrations/1715689232003_create view submission services log /up.sql @@ -0,0 +1,45 @@ +create or replace view public.submission_services_log as +with payments as ( + select + session_id, + payment_id::text as event_id, + 'Pay' as event_type, + initcap(status) as status, + '{}'::jsonb as response, + created_at + from payment_status + where status != 'created' + and created_at >= '2024-01-01' +), submissions as ( + select + (seil.request -> 'payload' -> 'payload' ->> 'sessionId')::uuid as session_id, + se.id as event_id, + case + when se.webhook_conf::text like '%bops%' then 'Submit to BOPS' + when se.webhook_conf::text like '%uniform%' then 'Submit to Uniform' + when se.webhook_conf::text like '%email-submission%' then 'Send to email' + when se.webhook_conf::text like '%upload-submission%' then 'Upload to AWS S3' + else se.webhook_conf::text + end as event_type, + case + when seil.status = 200 then 'Success' + else format('Failed (%s)', seil.status) + end as status, + seil.response::jsonb, + seil.created_at + from hdb_catalog.hdb_scheduled_events se + left join hdb_catalog.hdb_scheduled_event_invocation_logs seil on seil.event_id = se.id + where se.webhook_conf::text not like '%email/%' + and seil.created_at >= '2024-01-01' +), all_events as ( + select * from payments + union all + select * from submissions +) +SELECT + ls.flow_id, + ae.* +FROM all_events ae + left join public.lowcal_sessions ls on ls.id = ae.session_id +WHERE ls.flow_id is not null +order by ae.created_at desc;