-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: split submission_services_summary allow_list_answers into their own columns in view #2927
Merged
Mike-Heneghan
merged 2 commits into
main
from
mh/submission-services-summary-split-allow-list-answers
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...er_view_public_submission_services_summary_split_allow_list_answers_into_columns/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
-- Previous instance of view from hasura.planx.uk/migrations/1710431558909_alter_view_public_submission_services_summary_reinstate_allow_list_answers/up.sql | ||
|
||
drop view "public"."submission_services_summary"; | ||
|
||
create or replace view "public"."submission_services_summary" as | ||
with resumes_per_session as ( | ||
select | ||
session_id, | ||
count(id) as number_times_resumed | ||
from reconciliation_requests | ||
group by session_id | ||
), bops_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'id', bops_id, | ||
'submittedAt', created_at, | ||
'destinationUrl', destination_url | ||
) order by created_at desc | ||
) as bops_applications | ||
from bops_applications | ||
group by session_id | ||
), email_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'id', id, | ||
'recipient', recipient, | ||
'submittedAt', created_at | ||
) order by created_at desc | ||
) as email_applications | ||
from email_applications | ||
group by session_id | ||
), uniform_agg as ( | ||
select | ||
submission_reference, | ||
json_agg( | ||
json_build_object( | ||
'id', idox_submission_id, | ||
'submittedAt', created_at | ||
) order by created_at desc | ||
) as uniform_applications | ||
from uniform_applications | ||
group by submission_reference | ||
), payment_requests_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'id', id, | ||
'createdAt', created_at, | ||
'paidAt', paid_at, | ||
'govpayPaymentId', govpay_payment_id | ||
) order by created_at desc | ||
) as payment_requests | ||
from payment_requests | ||
group by session_id | ||
), payment_status_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'govpayPaymentId', payment_id, | ||
'createdAt', created_at, | ||
'status', status | ||
) order by created_at desc | ||
) as payment_status | ||
from payment_status | ||
group by session_id | ||
) | ||
select | ||
ls.id::text as session_id, | ||
t.slug as team_slug, | ||
f.slug as service_slug, | ||
ls.created_at, | ||
ls.submitted_at, | ||
(ls.submitted_at::date - ls.created_at::date) as session_length_days, | ||
ls.has_user_saved as user_clicked_save, | ||
rps.number_times_resumed, | ||
ls.allow_list_answers, | ||
case | ||
when pr.payment_requests::jsonb is not null and jsonb_array_length(pr.payment_requests::jsonb) > 0 | ||
then true | ||
else false | ||
end as user_invited_to_pay, | ||
pr.payment_requests, | ||
ps.payment_status, | ||
case | ||
when ba.bops_applications::jsonb is not null and jsonb_array_length(ba.bops_applications::jsonb) > 0 | ||
then true | ||
else false | ||
end as sent_to_bops, | ||
ba.bops_applications, | ||
case | ||
when ua.uniform_applications::jsonb is not null and jsonb_array_length(ua.uniform_applications::jsonb) > 0 | ||
then true | ||
else false | ||
end as sent_to_uniform, | ||
ua.uniform_applications, | ||
case | ||
when ea.email_applications::jsonb is not null and jsonb_array_length(ea.email_applications::jsonb) > 0 | ||
then true | ||
else false | ||
end as sent_to_email, | ||
ea.email_applications | ||
from lowcal_sessions ls | ||
left join flows f on f.id = ls.flow_id | ||
left join teams t on t.id = f.team_id | ||
left join resumes_per_session rps on rps.session_id = ls.id::text | ||
left join payment_requests_agg pr on pr.session_id = ls.id | ||
left join payment_status_agg ps on ps.session_id = ls.id | ||
left join bops_agg ba on ba.session_id = ls.id::text | ||
left join uniform_agg ua on ua.submission_reference = ls.id::text | ||
left join email_agg ea on ea.session_id = ls.id | ||
where f.slug is not null | ||
and t.slug is not null; | ||
|
||
-- After recreating the view grant Metabase access to it | ||
GRANT SELECT ON public.submission_services_summary TO metabase_read_only; |
125 changes: 125 additions & 0 deletions
125
...lter_view_public_submission_services_summary_split_allow_list_answers_into_columns/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
drop view "public"."submission_services_summary"; | ||
|
||
create or replace view "public"."submission_services_summary" as | ||
with resumes_per_session as ( | ||
select | ||
session_id, | ||
count(id) as number_times_resumed | ||
from reconciliation_requests | ||
group by session_id | ||
), bops_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'id', bops_id, | ||
'submittedAt', created_at, | ||
'destinationUrl', destination_url | ||
) order by created_at desc | ||
) as bops_applications | ||
from bops_applications | ||
group by session_id | ||
), email_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'id', id, | ||
'recipient', recipient, | ||
'submittedAt', created_at | ||
) order by created_at desc | ||
) as email_applications | ||
from email_applications | ||
group by session_id | ||
), uniform_agg as ( | ||
select | ||
submission_reference, | ||
json_agg( | ||
json_build_object( | ||
'id', idox_submission_id, | ||
'submittedAt', created_at | ||
) order by created_at desc | ||
) as uniform_applications | ||
from uniform_applications | ||
group by submission_reference | ||
), payment_requests_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'id', id, | ||
'createdAt', created_at, | ||
'paidAt', paid_at, | ||
'govpayPaymentId', govpay_payment_id | ||
) order by created_at desc | ||
) as payment_requests | ||
from payment_requests | ||
group by session_id | ||
), payment_status_agg as ( | ||
select | ||
session_id, | ||
json_agg( | ||
json_build_object( | ||
'govpayPaymentId', payment_id, | ||
'createdAt', created_at, | ||
'status', status | ||
) order by created_at desc | ||
) as payment_status | ||
from payment_status | ||
group by session_id | ||
) | ||
select | ||
ls.id::text as session_id, | ||
t.slug as team_slug, | ||
f.slug as service_slug, | ||
ls.created_at, | ||
ls.submitted_at, | ||
(ls.submitted_at::date - ls.created_at::date) as session_length_days, | ||
ls.has_user_saved as user_clicked_save, | ||
rps.number_times_resumed, | ||
ls.allow_list_answers, | ||
ls.allow_list_answers -> 'proposal.projectType' as proposal_project_type, | ||
ls.allow_list_answers -> 'application.declaration.connection' as application_declaration_connection, | ||
ls.allow_list_answers -> 'property.type' as property_type, | ||
ls.allow_list_answers -> 'drawBoundary.action' as draw_boundary_action, | ||
ls.allow_list_answers -> 'user.role' as user_role, | ||
ls.allow_list_answers -> 'property.constraints.planning' as property_constraints_planning, | ||
case | ||
when pr.payment_requests::jsonb is not null and jsonb_array_length(pr.payment_requests::jsonb) > 0 | ||
then true | ||
else false | ||
end as user_invited_to_pay, | ||
pr.payment_requests, | ||
ps.payment_status, | ||
case | ||
when ba.bops_applications::jsonb is not null and jsonb_array_length(ba.bops_applications::jsonb) > 0 | ||
then true | ||
else false | ||
end as sent_to_bops, | ||
ba.bops_applications, | ||
case | ||
when ua.uniform_applications::jsonb is not null and jsonb_array_length(ua.uniform_applications::jsonb) > 0 | ||
then true | ||
else false | ||
end as sent_to_uniform, | ||
ua.uniform_applications, | ||
case | ||
when ea.email_applications::jsonb is not null and jsonb_array_length(ea.email_applications::jsonb) > 0 | ||
then true | ||
else false | ||
end as sent_to_email, | ||
ea.email_applications | ||
from lowcal_sessions ls | ||
left join flows f on f.id = ls.flow_id | ||
left join teams t on t.id = f.team_id | ||
left join resumes_per_session rps on rps.session_id = ls.id::text | ||
left join payment_requests_agg pr on pr.session_id = ls.id | ||
left join payment_status_agg ps on ps.session_id = ls.id | ||
left join bops_agg ba on ba.session_id = ls.id::text | ||
left join uniform_agg ua on ua.submission_reference = ls.id::text | ||
left join email_agg ea on ea.session_id = ls.id | ||
where f.slug is not null | ||
and t.slug is not null; | ||
|
||
-- After recreating the view grant Metabase access to it | ||
GRANT SELECT ON public.submission_services_summary TO metabase_read_only; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: #2926 (comment)