chatwoot/config
Shivam Mishra 9967101b48
feat(rollup): add models and write path [1/3] (#13796)
## PR#1: Reporting events rollup — model and write path

Reporting queries currently hit the `reporting_events` table directly.
This works, but the table grows linearly with event volume, and
aggregation queries (counts, averages over date ranges) get
progressively slower as accounts age.

This PR introduces a pre-aggregated `reporting_events_rollups` table
that stores daily per-metric, per-dimension (account/agent/inbox)
totals. The write path is intentionally decoupled from the read path —
rollup rows are written inline from the event listener via upsert, and a
backfill service exists to rebuild historical data from raw events.
Nothing reads from this table yet.

The write path activates when an account has a `reporting_timezone` set
(new account setting). The `reporting_events_rollup` feature flag
controls only the future read path, not writes — so rollup data
accumulates silently once timezone is configured. A `MetricRegistry`
maps raw event names to rollup column semantics in one place, keeping
the write and (future) read paths aligned.

### What changed

- Migration for `reporting_events_rollups` with a unique composite index
for upsert
- `ReportingEventsRollup` model
- `reporting_timezone` account setting with IANA timezone validation
- `MetricRegistry` — single source of truth for event-to-metric mappings
- `RollupService` — real-time upsert from event listener
- `BackfillService` — rebuilds rollups for a given account + date from
raw events
- Rake tasks for interactive backfill and timezone setup
- `reporting_events_rollup` feature flag (disabled by default)

### How to test

1. Set a `reporting_timezone` on an account
(`Account.first.update!(reporting_timezone: 'Asia/Kolkata')`)
2. Resolve a conversation or trigger a first response
3. Check `ReportingEventsRollup.where(account_id: ...)` — rows should
appear
4. Run backfill: `bundle exec rake reporting_events_rollup:backfill` and
verify historical data populates

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2026-03-19 13:12:36 +05:30
..
agents feat: add resolve_conversation tool for Captain V2 scenarios (#13597) 2026-02-20 19:08:36 +05:30
environments chore: Improvements to codespaces (#11635) 2025-05-29 21:18:02 -06:00
initializers feat: distributed scheduling for version check job (#13042) 2026-03-17 02:27:49 -07:00
integration feat: notion OAuth setup (#11765) 2025-06-26 19:16:06 +05:30
languages feat: Updated public portal header design (#8089) 2023-11-08 17:56:59 -08:00
locales feat(rollup): add models and write path [1/3] (#13796) 2026-03-19 13:12:36 +05:30
app.yml Bump version to 4.12.0 2026-03-17 16:19:39 -07:00
application.rb Revert "chore: Upgrade Rails to 7.2.2 and update Gemfile dependencies (#11037)" 2026-02-03 21:09:42 -08:00
boot.rb Upgrade to rails 6 💎 (#11) 2019-08-19 13:49:57 +05:30
cable.yml fix: Redis 6 on Heroku breaks ActionCable config (#4269) 2022-03-24 19:25:07 +05:30
database.yml perf: enable active record connection pool reaper (#10866) 2025-03-17 19:27:05 -07:00
elastic_apm.yml chore: Support for Elastic APM (#5004) 2022-07-22 11:39:37 +02:00
environment.rb Initial Commit 2019-08-14 15:18:44 +05:30
features.yml feat: make assignment_v2 feature available to all accounts (#13764) 2026-03-11 13:46:53 +05:30
installation_config.yml fix: call authorization_error! on IMAP auth failures (#13560) (revert) (#13671) 2026-02-26 18:45:18 -08:00
llm.yml feat: add global config for captain settings (#13141) 2026-01-12 19:54:19 +05:30
markdown_embeds.yml feat: update bunny video support in HC (#13815) 2026-03-16 11:04:27 +05:30
newrelic.yml fix: logic error when setting new relic logging forwarding (#8687) 2024-01-11 21:05:04 +05:30
puma.rb chore: Fix puma configuration (#5023) 2022-07-12 12:27:33 +02:00
rds-ca-2019-root.pem chore: add aws rds root cert for tls connection (#3812) 2022-02-01 16:01:25 +05:30
routes.rb feat(whatsapp): add webhook registration and status endpoints (#13551) 2026-03-16 12:48:16 +05:30
schedule.yml feat: distributed scheduling for version check job (#13042) 2026-03-17 02:27:49 -07:00
scout_apm.yml chore: Load only required APMs (#6497) 2023-03-01 14:31:51 +05:30
secrets.yml Use secret_key_base from env 2019-08-15 23:08:36 +05:30
sidekiq.yml chore: add script to throttle bulkreindex job creation and increase meta timeouts(#12626) 2025-10-13 16:21:45 +05:30
spring.rb 🚨Fix Rubocop lint errors 2019-10-20 14:17:26 +05:30
storage.yml Revert "chore: Upgrade Rails to 7.2.2 and update Gemfile dependencies (#11037)" 2026-02-03 21:09:42 -08:00
vite.json feat: Vite + vue 3 💚 (#10047) 2024-10-02 00:36:30 -07:00