D95 · Notifications are in-app events, one row each, seen by permission at their pool, closed by their condition and filtered by severity for the higher-ups
Proposed · 2026-11-09 · zuki, in a CTO session reviewing v1's workflows; it binds when this page's pull request is merged · Answers #156's alerts row · Applies to every module that raises one, M1 to M7 · M2 line changed by D110
Decision: v2 has an in-app notification system. v1 has none, so nothing loads. Who sees a notification is computed from the access rules, never copied per person.
-
The tables:
Table Holds notification_typesA system catalogue, seeded like the permissions: the code, the module, the default severity, the permission that sees it, whether it escalates, and each role's default delivery notificationsOne row per event: its type, pool, subject (table and id), severity, an optional recipient, when it opened, who acknowledged it and when, and when it was resolved notification_receiptsOne row per member who read or dismissed it, made only when they do notification_preferencesA member's choice per module or type: live, digest or off, and the lowest severity they get live -
Who sees one: a member holding the type's permission at the notification's pool (R-ACC-09), through RLS. A notification with a recipient, such as "you are this work order's PIC", is seen only by that member. A role that changes changes what its holder sees.
-
Where one comes from: the business function that does the action calls
app.notifyin the same transaction, so a refused action notifies no one (D3); a pg_cron job raises the ones a date triggers, such as an expiring STNK or an overdue checkpoint. -
A condition closes its own notification. At most one is open per type and subject; when the condition ends (the checkpoint is done, the work order is routed), the function that ends it sets resolved_at, and it leaves the bell. A team-owned notification can be acknowledged by one member for the team, which is how #156's alerts work: D42's failed visit check is a notification type, not a table of its own.
-
Severity: info, action (someone has to do something) or urgent. An unresolved action notification becomes urgent once its type's time has passed, so the leaders see what is stuck, not every event.
-
The higher-ups' filter. admin, super_admin and viewer get urgent live and the rest in a daily digest by default; the teams get action and urgent live. A digest is one notification per member each morning, its counts per type and pool computed when it is made. Each member may choose their pools, modules and types, but can't turn off one sent to them by name.
-
The times are organization settings (R-SET): the escalation time of each escalating type, 24 hours by default, and the digest's hour, 07:00 in the organization's time. They aren't set per pool.
-
In-app only: a bell and a page, live through Supabase Realtime under RLS. Email or WhatsApp is a later decision.
-
No personal data in a row: a notification holds ids and counts; names are read under RLS when it is shown (D15). A resolved notification and its receipts are deleted after 90 days; they aren't business rows (P13).
-
The first types, each built with its module:
Module Types M1 You were given a role at a pool M2 STNK, KIR or insurance expiring in 30 days, then expired (D47) M3 Background check done; onboarding waiting for approval; a failed visit check (D42) M4 Handovers due today; a rental now returningM5 A car uncheckedwaiting for its BASTK (D92); a checkpoint due, then overdue (R-INSP-10); a work order waiting for its route; you are its PIC; the Leader's check waiting (preparation:approve, D94); a one-day repair past its day (D94); a claim's status changed; a gate pass waiting for approval; a repo request, a repo work order given to you, a car recoveredM6 A driver overdue; a payment waiting for approval; a surat hutang due; a new ETLE violation Stock Opname's missing cars stay alerts on its page (D93).
Why: zuki, 2026-11-09: v2 needs notifications, which v1 doesn't have; in-app only for now; admin, super_admin and viewer are the higher-ups, who mustn't be overloaded; the escalation times are organization settings with the CTO's defaults. One row per event, seen through the access rules, avoids a copy per member that goes stale when a role changes, and a condition that closes its own notification keeps the bell to what is still true. Escalation and the digest give the higher-ups what is stuck and a count of the rest.
Consequences:
- The foundation rides slice #584, so M1 to M6 add their types as they build their functions instead of M7 going back into each: DOC's rules (#589), then BE's four tables,
app.notify, the resolve and acknowledge functions, RLS and the two settings (#590). No type is seeded yet, and TL-DP-04 needs no change. - Each module's DOC pack names its types as rules; its BE pack seeds them and calls
app.notify. - M7 (#507): the bell, the page, the preferences, the escalation job and the digest. It may still follow cutover; the rows are raised from M1 on either way.
- #156's alerts row is answered by this decision; its other rows stay open.