Skip to main content
EmailEvent is an append-only event log for the outbound email lifecycle. One row is written per observed state transition — both internal (MailService called the provider) and provider-side (delivery and engagement webhooks from SendGrid). Multiple rows per logical send are correlated via message_id, a UUID generated at send time and echoed back by the provider in every webhook. The table is provider-agnostic: no column names SendGrid directly, so future provider swaps require no schema change. The entity is associated to a Workspace via a nullable SET NULL foreign key so bounce/suppression history outlives workspace deletion.
Internal object. Not currently exposed on the public REST API. The operations below describe the intended contract.

API operations

Data model

Attributes

Relationships

System-computed

  • email_event_id — gen_random_uuid() default at insert, never caller-supplied
  • received_at — set by MikroORM onCreate hook to new Date(); represents the DB write timestamp
  • workspace FK on delete SET NULL — workspace deletion orphans rows rather than cascading deletes, preserving suppression history
  • Partial unique index on (provider, provider_event_id) WHERE provider_event_id IS NOT NULL — idempotency guard for provider webhook retries; index maintained by Postgres, not application code
  • No created_at / updated_at / deleted_at — this entity is append-only (no soft-delete, no update semantics); created_at was dropped in Migration20260507121000 as redundant with received_at

Example

Source: apps/api/src/database/entities/EmailEvent.ts — migrations: apps/api/src/database/migrations/Migration20260507094935_email_events.ts, Migration20260507120000_email_events_workspace_set_null.ts, Migration20260507121000_email_events_drop_created_at.ts · domain: platform · tier: Activity