Skip to content

Commit

Permalink
chore: Add the preprod refresh and reports scripts to the Helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbali committed Apr 19, 2024
1 parent 17745d8 commit 67b4e9e
Show file tree
Hide file tree
Showing 11 changed files with 1,103 additions and 2 deletions.
48 changes: 48 additions & 0 deletions helm_deploy/REPORTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
This directory contains scripts and configuration to enable automated delivery of CSV reports via GovNotify.

With the exception of the Monthly Incomplete PER Report (see below) new jobs can be configured by replicating the config and cronjob files in each subfolder.

***Note: Where possible, use the read-replica database.*** The SQL in the configuration is executed directly against the database.

# CronJob File
Most of the cronjob can be copied wholesale when adding new reports, replacing the following as required:

`metadata.name`
The name of the configmap in the `configMapKeyRef` for each of the environment variables (except the first two which are in secrets) and for the `report-sql` volume.
The name of the configmap should match that of the `metadata.name` in the respective config file.

`spec.schedule` should be changed as needed. This is in UTC and as such will run at eg 8.30 AM in Summer when defined as `30 7 * * *`

# Config file:

Fields in the config file define the report and the content of the email.

- from-date: The date with which any `[FROM]` placeholders in the sql are replaced. This can be specified in relative terms "1 day ago" and is interpreted by GNU `date`
- to-date: As with from date. The interpreted data replaces any `[TO]` placeholders in the sql
- subject: The subject line of the outgoing email
- body: The line of text inserted into the email before the download link.
- filename: The filename of the email attachment. The `.csv` extension is automatically appended
- retention: The duration a file should be made available to download from GovNotify eg `1 week`. Max value is 78 weeks.
- confirm_email: True or false - Whether the recipient of a file must confirm the email to which it was sent before downloading the file. In most cases this should be true, see the [GovNotify guidance](https://docs.notifications.service.gov.uk/rest-api.html#ask-recipients-to-confirm-their-email-address-before-they-can-download-the-file) regarding this.
- recipients: Comma separated list of recipients to which the report is sent. An email is sent to each recipient individually
- report_sql: The SQL to run against the database. Use the placeholders `[FROM]` and `[TO]` to have the dates defined in the `from-date` and `to-date` keys subsituted in in the format `'YYY-MM-DD'`



# Placeholders

As described above, the SQL script will have any `[FROM]` or `[TO]` placeholders replaced by the date interpeted from the `from-date` and `to-date` keys in the config.
These dates and the current day's date are also available to be used in the email subject, body and filename in the following formats, using these placeholders:

- `[FROM_DATE]` The date defined by the `from-date` key in the configmap, in the format `YYYY-MM-DD`
- `[FROM_DATE_FULL]` The date defined by the `from-date` key in the configmap, as text eg `Wednesday, 17 April`
- `[TO_DATE]` The date defined by the `to-date` key in the configmap, in the format `YYYY-MM-DD`
- `[TO_DATE_FULL]` The date defined by the `to-date` key in the configmap, as text eg `Wednesday, 17 April`
- `[TODAY_DATE]` Today's date in the format `YYYY-MM-DD`
- `[TODAY_FULL]` Today's date as text eg `Wednesday, 17 April`


# Monthly Incomplete PER report

This report shouldn't be used as a template for creating any one-file reports as it is scripted differently to allow for multiple queries to be run before being combined as sheets in an xlsx.
It still uses parts of the scripts in `00-reporting-scripts` so changes to those will affect all reports.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- $fullName := printf "%s-%s" (include "generic-service.fullname" $) "create-temp-tables" | trunc 52 }}
{{- if .Values.scripts.preprodRefresh.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $fullName }}
data:
createTables.sql: |-
BEGIN;
CREATE TABLE framework_flags_temp (LIKE framework_flags);
CREATE TABLE framework_nomis_codes_temp (LIKE framework_nomis_codes);
CREATE TABLE framework_nomis_mappings_temp (LIKE framework_nomis_mappings);
CREATE TABLE framework_questions_temp (LIKE framework_questions);
CREATE TABLE framework_responses_temp (LIKE framework_responses);
CREATE TABLE frameworks_temp (LIKE frameworks);
CREATE TABLE framework_flags_responses_temp (LIKE framework_flags_responses);
CREATE TABLE framework_nomis_codes_questions_temp (LIKE framework_nomis_codes_questions);
CREATE TABLE framework_nomis_mappings_responses_temp (LIKE framework_nomis_mappings_responses);
CREATE TABLE locations_temp (LIKE locations);
CREATE TABLE moves_temp (LIKE moves);
CREATE TABLE journeys_temp (LIKE journeys);
CREATE TABLE people_temp (LIKE people);
CREATE TABLE profiles_temp (LIKE profiles);
CREATE TABLE person_escort_records_temp (LIKE person_escort_records);
CREATE TABLE court_hearings_temp (LIKE court_hearings);
CREATE TABLE allocation_complex_cases_temp (LIKE allocation_complex_cases);
CREATE TABLE allocations_temp (LIKE allocations);
CREATE TABLE assessment_questions_temp (LIKE assessment_questions);
CREATE TABLE categories_temp (LIKE categories);
CREATE TABLE documents_temp (LIKE documents);
CREATE TABLE ethnicities_temp (LIKE ethnicities);
CREATE TABLE flipper_features_temp (LIKE flipper_features);
CREATE TABLE flipper_gates_temp (LIKE flipper_gates);
CREATE TABLE genders_temp (LIKE genders);
CREATE TABLE locations_regions_temp (LIKE locations_regions);
CREATE TABLE nationalities_temp (LIKE nationalities);
CREATE TABLE nomis_alerts_temp (LIKE nomis_alerts);
CREATE TABLE notifications_temp (LIKE notifications);
CREATE TABLE populations_temp (LIKE populations);
CREATE TABLE regions_temp (LIKE regions);
CREATE TABLE subscriptions_temp (LIKE subscriptions);
CREATE TABLE supplier_locations_temp (LIKE supplier_locations);
CREATE TABLE suppliers_temp (LIKE suppliers);
CREATE TABLE youth_risk_assessments_temp (LIKE youth_risk_assessments);
CREATE TABLE generic_events_temp (LIKE generic_events);
-- CREATE TABLE versions_temp (LIKE versions);
COMMIT;
{{- end }}
Loading

0 comments on commit 67b4e9e

Please sign in to comment.