Skip to content

Commit

Permalink
pwnn-1965 feat(cms): add parent group to CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoaken committed May 8, 2024
1 parent d557dec commit 3210c8d
Show file tree
Hide file tree
Showing 4 changed files with 361 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class UpdateSupportCaseDataToVersion10 < ActiveRecord::Migration[7.1]
def change
update_view :support_case_data, version: 10, revert_to_version: 9
end
end
160 changes: 98 additions & 62 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_04_26_130505) do
ActiveRecord::Schema[7.1].define(version: 2024_04_28_232453) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"

Expand Down Expand Up @@ -423,8 +423,8 @@
t.string "title"
t.text "body"
t.string "slug"
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "created_at", precision: nil, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", precision: nil, default: -> { "CURRENT_TIMESTAMP" }, null: false
t.string "contentful_id"
t.text "sidebar"
t.string "breadcrumbs", default: [], array: true
Expand Down Expand Up @@ -848,7 +848,7 @@
t.string "ukprn"
t.string "telephone_number"
t.jsonb "local_authority_legacy"
t.datetime "opened_date"
t.datetime "opened_date", precision: nil
t.string "number"
t.string "rsc_region"
t.string "trust_name"
Expand Down Expand Up @@ -1165,6 +1165,55 @@
LEFT JOIN frameworks_providers fp ON ((fp.id = ff.provider_id)))
LEFT JOIN support_agents sa ON ((sa.id = fe.assignee_id)));
SQL
create_view "frameworks_framework_data", sql_definition: <<-SQL
SELECT ff.id AS framework_id,
ff.source,
ff.status,
ff.name,
ff.short_name,
ff.url,
ff.reference,
fp.name AS provider_name,
fp.short_name AS provider_short_name,
fpc.name AS provider_contact_name,
fpc.email AS provider_contact_email,
ff.provider_start_date,
ff.provider_end_date,
ff.dfe_start_date,
ff.dfe_review_date,
ff.sct_framework_owner,
ff.sct_framework_provider_lead,
(((sap.first_name)::text || ' '::text) || (sap.last_name)::text) AS procops_lead_name,
sap.email AS procops_lead_email,
(((saeo.first_name)::text || ' '::text) || (saeo.last_name)::text) AS e_and_o_lead_name,
saeo.email AS e_and_o_lead_email,
(ff.created_at)::date AS created_at,
(ff.updated_at)::date AS updated_at,
ff.dps,
ff.lot,
ff.provider_reference,
(ff.faf_added_date)::date AS faf_added_date,
(ff.faf_end_date)::date AS faf_end_date,
cats.categories,
CASE
WHEN (evals.has_evaluation IS NOT NULL) THEN 'Yes'::text
ELSE 'No'::text
END AS has_evaluation
FROM ((((((frameworks_frameworks ff
LEFT JOIN frameworks_providers fp ON ((ff.provider_id = fp.id)))
LEFT JOIN frameworks_provider_contacts fpc ON ((ff.provider_contact_id = fpc.id)))
LEFT JOIN support_agents sap ON ((ff.proc_ops_lead_id = sap.id)))
LEFT JOIN support_agents saeo ON ((ff.e_and_o_lead_id = saeo.id)))
LEFT JOIN ( SELECT ffc.framework_id,
jsonb_agg(sc.title) AS categories
FROM (frameworks_framework_categories ffc
LEFT JOIN support_categories sc ON ((sc.id = ffc.support_category_id)))
GROUP BY ffc.framework_id) cats ON ((cats.framework_id = ff.id)))
LEFT JOIN ( SELECT ffe.framework_id,
count(ffe.id) AS has_evaluation
FROM frameworks_evaluations ffe
GROUP BY ffe.framework_id) evals ON ((evals.framework_id = ff.id)));
SQL
create_view "support_case_data", sql_definition: <<-SQL
SELECT sc.id AS case_id,
sc.ref AS case_ref,
Expand Down Expand Up @@ -1206,6 +1255,8 @@
se.urn AS organisation_urn,
se.ukprn AS organisation_ukprn,
se.rsc_region AS organisation_rsc_region,
se.trust_name AS parent_group_name,
se.trust_code AS parent_group_ukprn,
se.local_authority_name AS organisation_local_authority_name,
se.local_authority_code AS organisation_local_authority_code,
se.gor_name,
Expand All @@ -1214,10 +1265,12 @@
se.organisation_status,
se.egroup_status AS establishment_group_status,
se.establishment_type,
array_length(fr.school_urns, 1) AS request_num_schools,
replace(btrim((fr.school_urns)::text, '{}"'::text), ','::text, ', '::text) AS request_school_urns,
array_length(cr.school_urns, 1) AS case_num_schools,
replace(btrim((cr.school_urns)::text, '{}"'::text), ','::text, ', '::text) AS case_school_urns,
array_length(fr.school_urns, 1) AS framework_request_num_schools,
replace(TRIM(BOTH '{}"'::text FROM (fr.school_urns)::text), ','::text, ', '::text) AS framework_request_school_urns,
array_length(cr.school_urns, 1) AS case_request_num_schools,
replace(TRIM(BOTH '{}"'::text FROM (cr.school_urns)::text), ','::text, ', '::text) AS case_request_school_urns,
jsonb_array_length(cps.participating_schools) AS case_num_participating_schools,
replace(TRIM(BOTH '[]'::text FROM (cps.participating_schools)::text), '"'::text, ''::text) AS case_participating_school_urns,
sf.name AS framework_name,
sp.reason_for_route_to_market,
sp.required_agreement_type,
Expand All @@ -1240,7 +1293,7 @@
ps.created_at AS participation_survey_date,
es.created_at AS exit_survey_date,
sir.referrer
FROM (((((((((((((((((support_cases sc
FROM ((((((((((((((((((support_cases sc
LEFT JOIN ( SELECT sa_1.id,
sa_1.first_name,
sa_1.last_name
Expand All @@ -1267,6 +1320,11 @@
cr_1.support_case_id,
cr_1.school_urns
FROM case_requests cr_1) cr ON ((sc.id = cr.support_case_id)))
LEFT JOIN ( SELECT sco.support_case_id,
jsonb_agg(so.urn) AS participating_schools
FROM (support_case_organisations sco
LEFT JOIN support_organisations so ON ((so.id = sco.support_organisation_id)))
GROUP BY sco.support_case_id) cps ON ((cps.support_case_id = sc.id)))
LEFT JOIN support_interactions si ON ((si.id = ( SELECT i.id
FROM support_interactions i
WHERE (i.case_id = sc.id)
Expand All @@ -1280,15 +1338,18 @@
organisations.gor_name,
organisations.urn,
organisations.ukprn,
organisations.trust_name,
parent.ukprn AS trust_code,
organisations.status AS organisation_status,
NULL::integer AS egroup_status,
NULL::character varying AS uid,
organisations.phase,
etypes.name AS establishment_type,
'Support::Organisation'::text AS source
FROM ((support_organisations organisations
FROM (((support_organisations organisations
JOIN support_establishment_types etypes ON ((etypes.id = organisations.establishment_type_id)))
JOIN local_authorities ON ((local_authorities.id = organisations.local_authority_id)))
JOIN support_establishment_groups parent ON (((parent.uid)::text = (organisations.trust_code)::text)))
UNION ALL
SELECT egroups.id,
egroups.name,
Expand All @@ -1298,14 +1359,34 @@
NULL::character varying AS gor_name,
NULL::character varying AS urn,
egroups.ukprn,
egroups.name AS trust_name,
egroups.ukprn AS trust_code,
NULL::integer AS organisation_status,
egroups.status AS egroup_status,
egroups.uid,
NULL::integer AS phase,
egtypes.name AS establishment_type,
'Support::EstablishmentGroup'::text AS source
FROM (support_establishment_groups egroups
JOIN support_establishment_group_types egtypes ON ((egtypes.id = egroups.establishment_group_type_id)))) se ON (((sc.organisation_id = se.id) AND ((sc.organisation_type)::text = se.source))))
JOIN support_establishment_group_types egtypes ON ((egtypes.id = egroups.establishment_group_type_id)))
UNION ALL
SELECT la.id,
la.name,
NULL::character varying AS rsc_region,
la.name AS local_authority_name,
la.la_code AS local_authority_code,
NULL::character varying AS gor_name,
NULL::character varying AS urn,
NULL::character varying AS ukprn,
NULL::character varying AS trust_name,
NULL::character varying AS trust_code,
NULL::integer AS organisation_status,
NULL::integer AS egroup_status,
NULL::character varying AS uid,
NULL::integer AS phase,
'Local Authority'::character varying AS establishment_type,
'LocalAuthority'::text AS source
FROM local_authorities la) se ON (((sc.organisation_id = se.id) AND ((sc.organisation_type)::text = se.source))))
LEFT JOIN support_categories cat ON ((sc.category_id = cat.id)))
LEFT JOIN support_procurements sp ON ((sc.procurement_id = sp.id)))
LEFT JOIN support_procurement_stages sps ON ((sc.procurement_stage_id = sps.id)))
Expand All @@ -1315,63 +1396,18 @@
LEFT JOIN ( SELECT si_1.created_at,
si_1.case_id
FROM support_interactions si_1
WHERE ((si_1.event_type = 3) AND ((si_1.additional_data ->> 'email_template'::text) = 'fd89b69e-7ff9-4b73-b4c4-d8c1d7b93779'::text))) ps ON ((si.case_id = ps.case_id)))
WHERE ((si_1.event_type = 3) AND ((si_1.additional_data ->> 'email_template'::text) = 'fd89b69e-7ff9-4b73-b4c4-d8c1d7b93779'::text))
ORDER BY si_1.created_at
LIMIT 1) ps ON ((si.case_id = ps.case_id)))
LEFT JOIN ( SELECT si_1.created_at,
si_1.case_id
FROM support_interactions si_1
WHERE ((si_1.event_type = 3) AND ((si_1.additional_data ->> 'email_template'::text) = '134bc268-2c6b-4b74-b6f4-4a58e22d6c8b'::text))) es ON ((si.case_id = es.case_id)))
LEFT JOIN ( SELECT (si_1.additional_data ->> 'referrer'::text) AS referrer,
si_1.case_id
FROM support_interactions si_1
WHERE (si_1.event_type = 8)) sir ON ((si.case_id = sir.case_id)));
SQL
create_view "frameworks_framework_data", sql_definition: <<-SQL
SELECT ff.id AS framework_id,
ff.source,
ff.status,
ff.name,
ff.short_name,
ff.url,
ff.reference,
fp.name AS provider_name,
fp.short_name AS provider_short_name,
fpc.name AS provider_contact_name,
fpc.email AS provider_contact_email,
ff.provider_start_date,
ff.provider_end_date,
ff.dfe_start_date,
ff.dfe_review_date,
ff.sct_framework_owner,
ff.sct_framework_provider_lead,
(((sap.first_name)::text || ' '::text) || (sap.last_name)::text) AS procops_lead_name,
sap.email AS procops_lead_email,
(((saeo.first_name)::text || ' '::text) || (saeo.last_name)::text) AS e_and_o_lead_name,
saeo.email AS e_and_o_lead_email,
(ff.created_at)::date AS created_at,
(ff.updated_at)::date AS updated_at,
ff.dps,
ff.lot,
ff.provider_reference,
(ff.faf_added_date)::date AS faf_added_date,
(ff.faf_end_date)::date AS faf_end_date,
cats.categories,
CASE
WHEN (evals.has_evaluation IS NOT NULL) THEN 'Yes'::text
ELSE 'No'::text
END AS has_evaluation
FROM ((((((frameworks_frameworks ff
LEFT JOIN frameworks_providers fp ON ((ff.provider_id = fp.id)))
LEFT JOIN frameworks_provider_contacts fpc ON ((ff.provider_contact_id = fpc.id)))
LEFT JOIN support_agents sap ON ((ff.proc_ops_lead_id = sap.id)))
LEFT JOIN support_agents saeo ON ((ff.e_and_o_lead_id = saeo.id)))
LEFT JOIN ( SELECT ffc.framework_id,
jsonb_agg(sc.title) AS categories
FROM (frameworks_framework_categories ffc
LEFT JOIN support_categories sc ON ((sc.id = ffc.support_category_id)))
GROUP BY ffc.framework_id) cats ON ((cats.framework_id = ff.id)))
LEFT JOIN ( SELECT ffe.framework_id,
count(ffe.id) AS has_evaluation
FROM frameworks_evaluations ffe
GROUP BY ffe.framework_id) evals ON ((evals.framework_id = ff.id)));
WHERE (si_1.event_type = 8)
ORDER BY si_1.created_at
LIMIT 1) sir ON ((si.case_id = sir.case_id)));
SQL
end
Loading

0 comments on commit 3210c8d

Please sign in to comment.