Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP-1676: Document beforeafter SQL function #2364

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
```
Loading