Skip to content

Commit

Permalink
docs: Document beforeafter SQL function (#2364)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbali authored Oct 14, 2024
1 parent 0f8c697 commit 8dca8b9
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions helm_deploy/REPORTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ With the exception of the Monthly Incomplete PER Report (see below) new jobs can

***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:

Expand All @@ -13,6 +14,7 @@ The name of the configmap should match that of the `metadata.name` in the respec

`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.
Expand All @@ -28,7 +30,6 @@ Fields in the config file define the report and the content of the email.
- 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.
Expand All @@ -43,8 +44,34 @@ These dates and the current day's date are also available to be used in the emai
- `[LAST_MONTH]` Last month's name and year eg `April 2023`



# 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.
It still uses parts of the scripts in `00-reporting-scripts` so changes to those will affect all reports.


# Required function

For the weekly cancelled move reports to work, this function must exist in the database:

```
CREATE OR REPLACE FUNCTION public.beforeafter(
interval)
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
BEGIN
if $1 > interval '0 seconds' then
return 'Before cutoff ('|| $1 || ')';
else
return 'After cutoff (' || ($1 * -1) || ')';
end if;
END;
$BODY$;
ALTER FUNCTION public.beforeafter(interval)
OWNER TO "cpLOUozNLn";
```

0 comments on commit 8dca8b9

Please sign in to comment.