-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create a
submission_services_summary
database view for analyt…
…ics (#2430)
- Loading branch information
1 parent
8e0df7f
commit 7155fd1
Showing
3 changed files
with
51 additions
and
0 deletions.
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
1 change: 1 addition & 0 deletions
1
hasura.planx.uk/migrations/1700072112794_create_view_submission_services_summary/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 @@ | ||
DROP VIEW public.submission_services_summary CASCADE; |
47 changes: 47 additions & 0 deletions
47
hasura.planx.uk/migrations/1700072112794_create_view_submission_services_summary/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,47 @@ | ||
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 | ||
) | ||
select | ||
ls.id 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, | ||
case | ||
when pr.id is null | ||
then false | ||
else true | ||
end as user_invited_to_pay, | ||
case | ||
when ba.bops_id is null | ||
then false | ||
else true | ||
end as sent_to_bops, | ||
case | ||
when ua.idox_submission_id is null | ||
then false | ||
else true | ||
end as sent_to_uniform, | ||
case | ||
when ea.id is null | ||
then false | ||
else true | ||
end as sent_to_email | ||
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 pr on pr.session_id = ls.id | ||
left join bops_applications ba on ba.session_id = ls.id::text | ||
left join uniform_applications ua on ua.submission_reference = ls.id::text | ||
left join email_applications ea on ea.session_id = ls.id | ||
where f.slug IS NOT NULL | ||
and t.slug IS NOT NULL; |