Persistence

Architectural Context

The Persistence Layer houses the Entity Framework Core infrastructure specific to the MILTON.DocumentGenerator service.

While the central MILTON.Api service is the authoritative owner of the canonical Document and Content Block states, the Document Generator service maintains its own isolated PostgreSQL database schema (docgen-db).

Intent and Architecture

The Document Generator service is largely message-driven and processes work entirely asynchronously via Wolverine. The docgen-db database serves two critical functions:

  1. Wolverine Infrastructure: It provides the backing store for Wolverine’s durable outbox, inbox, and saga persistence. This ensures that in the event of a worker crash, inflight messages and saga states are flawlessly recovered without data loss.
  2. Operational Telemetry: It stores locally owned entities, like the DocumentGenerationRecord, which acts as an observability journal for document generation runs.
erDiagram
    DocGenDbContext ||--o{ DocumentGenerationRecord : "Manages"
    DocGenDbContext ||--o{ Wolverine_Sagas : "Manages via Wolverine"
    DocGenDbContext ||--o{ Wolverine_Envelopes : "Manages via Wolverine"
    
    DocumentGenerationRecord {
        Guid Id PK
        Guid DocumentId FK "Refers to API Domain"
        String Status
        DateTimeOffset StartedAt
        DateTimeOffset CompletedAt
        String Error
    }

Key Components

DocGenDbContext

The custom Entity Framework Core DbContext for the Document Generator service. It has no knowledge of the API’s entities. It provides the integration point for Wolverine’s Postgres persistence and maps local tables. Migrations for this context are applied on startup by the isolated MILTON.DocumentGeneratorMigrationService.

DocGenDbContextFactory

A design-time factory utilized by the dotnet ef CLI tools. It enables scaffolding and adding migrations to the docgen-db offline by supplying a localhost fallback connection string, mirroring the design pattern used in the main API.

DocumentGenerationRecord

The primary relational entity owned directly by the Document Generator. It acts as an observability journal, tracking the lifecycle status (Pending, Running, Completed, Failed) and execution times of saga-driven generation runs. This record seeds the schema and serves as the template for any future domain tables owned strictly by the document generator workers.

0 items under this folder.