mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 07:21:13 -05:00
This is functionally very similar to query_service_sms_usage_for_year, except this query filters by organisation and returns for all live services within that organisation. To ensure that the cumulative free allowance counter resets properly for each service, we use the `partition_by` flag to group up the window function[^1]. This magically handles all the free allowances independently for each service. [^1]: https://www.postgresql.org/docs/current/tutorial-window.html Co-authored-by: Leo Hemsted <leo.hemsted@digital.cabinet-office.gov.uk>