From 06e01756676637d0fbb433a15c859d17454b5e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 21 Nov 2024 10:53:03 +0000 Subject: [PATCH] chore: Save applicant research opt in query as view (#3996) --- hasura.planx.uk/metadata/tables.yaml | 3 ++ .../down.sql | 3 ++ .../up.sql | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/down.sql create mode 100644 hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/up.sql diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index ea03c776ed..3a24978694 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -94,6 +94,9 @@ - table: name: analytics_summary schema: public +- table: + name: applicant_research_opt_in_view + schema: public - table: name: blpu_codes schema: public diff --git a/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/down.sql b/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/down.sql new file mode 100644 index 0000000000..3da145bdbc --- /dev/null +++ b/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/down.sql @@ -0,0 +1,3 @@ +comment on view "public"."applicant_research_opt_in_view" is NULL; + +DROP VIEW applicant_research_opt_in_view; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/up.sql b/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/up.sql new file mode 100644 index 0000000000..17e0b04db8 --- /dev/null +++ b/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/up.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE VIEW applicant_research_opt_in_view AS +WITH data AS ( + SELECT + ls.id, + ls.email, + ls.created_at AS application_started_at, + ls.submitted_at, + ls.data->'passport'->'data'->>'applicant.name.last' AS last_name, + ls.data->'passport'->'data'->>'applicant.name.first' AS first_name, + f.name AS flow_name, + t.name AS team_name + FROM + lowcal_sessions ls + JOIN + flows f ON ls.flow_id = f.id + JOIN + teams t ON t.id = f.team_id + WHERE + ls.data->'passport'->'data'->>'applicant.researchOptIn' = '["true"]' +) +SELECT + * +FROM + data +WHERE + last_name IS NOT NULL + AND first_name IS NOT NULL; + +comment on view "public"."applicant_research_opt_in_view" is E'Temporary view to expose a list of applicants to opt in to user research during the 2024/25 pilot. Used to generate a CSV report bi-weekly.'; \ No newline at end of file