From ff00c7b71bd1d34e6a02491c165b6376128808ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 21 Nov 2024 10:15:15 +0000 Subject: [PATCH 1/2] chore: Save applicant research opt in query as view --- hasura.planx.uk/metadata/tables.yaml | 3 +++ .../down.sql | 1 + .../up.sql | 27 +++++++++++++++++++ 3 files changed, 31 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..2ea11370af --- /dev/null +++ b/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/down.sql @@ -0,0 +1 @@ +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..5fcc7a93fc --- /dev/null +++ b/hasura.planx.uk/migrations/1732184010002_applicant_research_opt_in_view/up.sql @@ -0,0 +1,27 @@ +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; From d0edb8263a46f419214b52cbfad420ad7cc2495f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Thu, 21 Nov 2024 10:18:11 +0000 Subject: [PATCH 2/2] chore: Add comment --- .../1732184010002_applicant_research_opt_in_view/down.sql | 2 ++ .../1732184010002_applicant_research_opt_in_view/up.sql | 2 ++ 2 files changed, 4 insertions(+) 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 index 2ea11370af..3da145bdbc 100644 --- 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 @@ -1 +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 index 5fcc7a93fc..17e0b04db8 100644 --- 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 @@ -25,3 +25,5 @@ FROM 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