From a4d0cd63194dc4477aa922332a03838d35db5437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 15 May 2024 19:46:33 +0100 Subject: [PATCH] chore: Replace `team.name` for `team.slug` in `feedback_summary` view (#3152) --- .../1715784133713_run_sql_migration/down.sql | 51 +++++++++++++++++++ .../1715784133713_run_sql_migration/up.sql | 49 ++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 hasura.planx.uk/migrations/1715784133713_run_sql_migration/down.sql create mode 100644 hasura.planx.uk/migrations/1715784133713_run_sql_migration/up.sql diff --git a/hasura.planx.uk/migrations/1715784133713_run_sql_migration/down.sql b/hasura.planx.uk/migrations/1715784133713_run_sql_migration/down.sql new file mode 100644 index 0000000000..785cd8b54e --- /dev/null +++ b/hasura.planx.uk/migrations/1715784133713_run_sql_migration/down.sql @@ -0,0 +1,51 @@ +-- Previous iteration of feedback_summary from planx-new/hasura.planx.uk/migrations/1707234695689_create_view_feedback_summary/up.sql + +CREATE OR REPLACE VIEW "public"."feedback_summary" AS +SELECT + fb.id AS feedback_id, + t.name AS team, + f.slug AS service_slug, + fb.created_at, + fb.node_id, + fb.device, + fb.user_context, + fb.user_comment, + fb.feedback_type, + fb.status, + fb.node_type, + COALESCE( + published_flow_node.data ->> 'title', + published_flow_node.data ->> 'text', + published_flow_node.data ->> 'flagSet' + ) AS node_title, + published_flow_node.data ->> 'description' AS node_text, + published_flow_node.data ->> 'info' AS help_text, + published_flow_node.data ->> 'policyRef' AS help_sources, + published_flow_node.data ->> 'howMeasured' AS help_definition, + COALESCE( + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'single_line_address', + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'title' + ) AS address, + (fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'uprn') AS uprn, + (fb.user_data -> 'passport' -> 'data' ->> 'proposal.projectType') AS project_type, + (fb.user_data -> 'passport' -> 'data' ->> 'property.constraints.planning') AS intersecting_constraints, + published_flow_node.data AS node_data +FROM + feedback fb +LEFT JOIN + flows f ON f.id = fb.flow_id +LEFT JOIN + teams t ON t.id = fb.team_id +LEFT JOIN LATERAL + ( + SELECT + (published_flows.data -> fb.node_id) -> 'data' AS data + FROM + published_flows + WHERE + published_flows.flow_id = fb.flow_id + AND published_flows.created_at < fb.created_at + ORDER BY + published_flows.created_at DESC + LIMIT 1 + ) AS published_flow_node ON true; diff --git a/hasura.planx.uk/migrations/1715784133713_run_sql_migration/up.sql b/hasura.planx.uk/migrations/1715784133713_run_sql_migration/up.sql new file mode 100644 index 0000000000..3506bf6e00 --- /dev/null +++ b/hasura.planx.uk/migrations/1715784133713_run_sql_migration/up.sql @@ -0,0 +1,49 @@ +CREATE OR REPLACE VIEW "public"."feedback_summary" AS +SELECT + fb.id AS feedback_id, + t.slug AS team, + f.slug AS service_slug, + fb.created_at, + fb.node_id, + fb.device, + fb.user_context, + fb.user_comment, + fb.feedback_type, + fb.status, + fb.node_type, + COALESCE( + published_flow_node.data ->> 'title', + published_flow_node.data ->> 'text', + published_flow_node.data ->> 'flagSet' + ) AS node_title, + published_flow_node.data ->> 'description' AS node_text, + published_flow_node.data ->> 'info' AS help_text, + published_flow_node.data ->> 'policyRef' AS help_sources, + published_flow_node.data ->> 'howMeasured' AS help_definition, + COALESCE( + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'single_line_address', + fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'title' + ) AS address, + (fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'uprn') AS uprn, + (fb.user_data -> 'passport' -> 'data' ->> 'proposal.projectType') AS project_type, + (fb.user_data -> 'passport' -> 'data' ->> 'property.constraints.planning') AS intersecting_constraints, + published_flow_node.data AS node_data +FROM + feedback fb +LEFT JOIN + flows f ON f.id = fb.flow_id +LEFT JOIN + teams t ON t.id = fb.team_id +LEFT JOIN LATERAL + ( + SELECT + (published_flows.data -> fb.node_id) -> 'data' AS data + FROM + published_flows + WHERE + published_flows.flow_id = fb.flow_id + AND published_flows.created_at < fb.created_at + ORDER BY + published_flows.created_at DESC + LIMIT 1 + ) AS published_flow_node ON true;