Notification Persistence and Repositories
Summary
Persistence is EF Core over PostgreSQL in the notification schema. Callers use NotificationDbContext directly; there is no repository or unit-of-work abstraction. The context intentionally applies no global tenant query filter.
Entities and tables
| Entity | Table | Purpose (verified) |
|---|---|---|
NotificationTemplate | NotificationTemplates | Versioned per-tenant/global subject+body templates |
NotificationRecipient | NotificationRecipients | Directory of resolved recipients |
NotificationMessage | NotificationMessages | One rendered message per channel+recipient |
NotificationDeliveryAttempt | NotificationDeliveryAttempts | Append-only per-attempt record |
NotificationPreference | NotificationPreferences | Per-recipient channel opt-outs |
NotificationAuditLog | NotificationAuditLog | Append-only stage audit trail |
ProcessedIntegrationEvent | ProcessedIntegrationEvents | Idempotency ledger, unique on EventId |
Key constraints and indexes
The model configures a unique index on (TenantId, TemplateKey, Channel, Version) for templates, a unique index on (TenantId, RecipientType, ExternalRef) for recipients, a unique preference scope index, a unique EventId on the idempotency ledger, and supporting indexes on message recipient/status, event id, correlation and audit occurrence. Length limits and a text column type for bodies are declared explicitly.
Access pattern
NotificationDispatcher, TemplateEngine, PreferenceEvaluator and the endpoints obtain NotificationDbContext via DI and issue LINQ directly. Writes call SaveChangesAsync; reads use AsNoTracking. The dispatcher persists incrementally (recipient, then each message, then attempts and audit) rather than in one transaction.
Design-time factory
NotificationDbContextFactory provides a design-time connection for dotnet ef migrations, defaulting to a local connection when the environment variable is absent.
Verified absence
There are no IRepository, INotificationRepository, generic repository, specification objects or unit-of-work types. The DbContext is the persistence abstraction.
Requires Confirmation
Production database sizing, retention policy for append-only tables and index adequacy under load require confirmation.
Source References
microservices/src/notification-service/Infrastructure/NotificationDbContext.csmicroservices/src/notification-service/Domain/NotificationEntities.csmicroservices/src/notification-service/Infrastructure/Migrations/NotificationDbContextModelSnapshot.cs
Related Articles
See Also
Keywords
Repositories, persistence, DbContext, entities, indexes, verified absence.
Revision Information
- Status: Draft
- Last reviewed: 2026-07-21
- Next review: 2026-10-21