From 15047dabea03882921ce2e87a7e44a2273e05bd3 Mon Sep 17 00:00:00 2001 From: Toby Privett Date: Mon, 2 Dec 2024 10:48:11 +0000 Subject: [PATCH] Lowercase SQL keywords in case `FROM` is causing a problem --- ...1-weekly-cancelled-court-moves-config.yaml | 38 +++++++++---------- .../01-weekly-cancelled-moves-config.yaml | 38 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-court-moves/01-weekly-cancelled-court-moves-config.yaml b/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-court-moves/01-weekly-cancelled-court-moves-config.yaml index 9b068569c..cff932f85 100644 --- a/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-court-moves/01-weekly-cancelled-court-moves-config.yaml +++ b/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-court-moves/01-weekly-cancelled-court-moves-config.yaml @@ -13,32 +13,30 @@ data: retention: "1 week" confirm_email: "true" report_sql: |- - SELECT m.status, + select m.status, m.reference, m.move_type, m.date, - f.title AS from_loc, - t.title AS to_loc, - COALESCE(person.nomis_prison_number, person.prison_number) AS prison_number, - COALESCE(person.last_name, '(Allocation)') AS last_name, + f.title as from_loc, + t.title as to_loc, + coalesce(person.nomis_prison_number, person.prison_number) as prison_number, + coalesce(person.last_name, '(Allocation)') as last_name, m.created_at, m.updated_at, m.cancellation_reason, m.cancellation_reason_comment, - e.created_at AS cancelled_at, e.created_by AS cancelled_by, - (SELECT EXISTS (select true FROM journeys where move_id = m.id AND billable = true limit 1)::boolean) AS journey_billable, - beforeafter((m.date::timestamp + interval '6 hours') - e.created_at) AS difference, - s.name AS journey_supplier - FROM moves m - LEFT JOIN profiles pro ON m.profile_id = pro.id - LEFT JOIN person_escort_records per ON pro.id = per.profile_id - LEFT JOIN people person ON pro.person_id = person.id - LEFT JOIN locations f ON m.FROM_location_id = f.id - LEFT JOIN locations t ON m.to_location_id = t.id - LEFT JOIN generic_events e ON e.eventable_type = 'Move' AND e.eventable_id = m.id AND type = 'GenericEvent::MoveCancel' - LEFT JOIN suppliers s ON m.supplier_id = s.id - WHERE m.date BETWEEN '2024-11-25' AND '2024-12-02' - AND m.status = 'cancelled' - AND m.move_type = 'court_appearance' + e.created_at as cancelled_at, e.created_by as cancelled_by, + (select exists (select true from journeys where move_id = m.id and billable = true limit 1)::boolean) as journey_billable, + beforeafter((m.date::timestamp + interval '6 hours') - e.created_at) as difference, + s.name as journey_supplier + from moves m + left join profiles pro on m.profile_id = pro.id + left join person_escort_records per on pro.id = per.profile_id + left join people person on pro.person_id = person.id + left join locations f on m.FROM_location_id = f.id + left join locations t on m.to_location_id = t.id + left join generic_events e on e.eventable_type = 'Move' and e.eventable_id = m.id and type = 'GenericEvent::MoveCancel' + left join suppliers s on m.supplier_id = s.id + where m.date between '[FROM]' and '[TO]' and m.status = 'cancelled' and m.move_type = 'court_appearance' ORDER BY date, last_name, prison_number {{- end }} diff --git a/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-moves/01-weekly-cancelled-moves-config.yaml b/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-moves/01-weekly-cancelled-moves-config.yaml index 219223381..16042240e 100644 --- a/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-moves/01-weekly-cancelled-moves-config.yaml +++ b/helm_deploy/hmpps-book-secure-move-api/templates/reports/weekly-cancelled-moves/01-weekly-cancelled-moves-config.yaml @@ -13,30 +13,30 @@ data: retention: "1 week" confirm_email: "true" report_sql: |- - SELECT m.status, + select m.status, m.reference, m.move_type, m.date, - f.title AS from_loc, - t.title AS to_loc, - COALESCE(person.nomis_prison_number, person.prison_number) AS prison_number, - COALESCE(person.last_name, '(Allocation)') AS last_name, + f.title as from_loc, + t.title as to_loc, + coalesce(person.nomis_prison_number, person.prison_number) as prison_number, + coalesce(person.last_name, '(Allocation)') as last_name, m.created_at, m.updated_at, m.cancellation_reason, m.cancellation_reason_comment, - e.created_at AS cancelled_at, e.created_by AS cancelled_by, - (SELECT EXISTS (select true FROM journeys where move_id = m.id AND billable = true limit 1)::boolean) AS journey_billable, - beforeafter((m.date::timestamp + interval '6 hours') - e.created_at) AS difference, - s.name AS journey_supplier - FROM moves m - LEFT JOIN profiles pro ON m.profile_id = pro.id - LEFT JOIN person_escort_records per ON pro.id = per.profile_id - LEFT JOIN people person ON pro.person_id = person.id - LEFT JOIN locations f ON m.FROM_location_id = f.id - LEFT JOIN locations t ON m.to_location_id = t.id - LEFT JOIN generic_events e ON e.eventable_type = 'Move' AND e.eventable_id = m.id AND type = 'GenericEvent::MoveCancel' - LEFT JOIN suppliers s ON m.supplier_id = s.id - WHERE m.date BETWEEN '[FROM]' AND '[TO]' AND m.status = 'cancelled' - ORDER BY date, last_name, prison_number + e.created_at as cancelled_at, e.created_by as cancelled_by, + (select exists (select t from journeys where move_id = m.id and billable = true limit 1)::boolean) as journey_billable, + beforeafter((m.date::timestamp + interval '6 hours') - e.created_at) as difference, + s.name as journey_supplier + from moves m + left join profiles pro on m.profile_id = pro.id + left join person_escort_records per on pro.id = per.profile_id + left join people person on pro.person_id = person.id + left join locations f on m.FROM_location_id = f.id + left join locations t on m.to_location_id = t.id + left join generic_events e on e.eventable_type = 'Move' and e.eventable_id = m.id and type = 'GenericEvent::MoveCancel' + left join suppliers s on m.supplier_id = s.id + where m.date between '[FROM]' and '[TO]' and m.status = 'cancelled' + order by date, last_name, prison_number {{- end }}