PostgreSQL persistence provider (D-0024) #5
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/postgres-persistence"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
Implements the PostgreSQL persistence provider per D-0024, replacing the "in-memory until the DB decision" gap with real durable shared persistence.
Viegard.Persistence.Postgres:ViegardDbContext+InitialSchemamigration: raw observations (payload inline), events (jsonb entities/payload with polymorphic discriminators), incidents, classifications, decisions, actions, audit records, corrections, queue telemetry, source offsets, and the queue message/counter tables.PostgresWorkQueue: durable broker-semantics queue:FOR UPDATE SKIP LOCKEDvisibility-timeout leases, delivery counting with dead-lettering enforced at lease time (a crashed consumer's expired leases still count, so poison messages can never redeliver forever),LISTEN/NOTIFYwakeups with a fallback poll, per-queue counters for D-0012 telemetry.PostgresCommandQueuerides the same mechanics for admin commands.DatabaseOptions+ validator: the DB password is a named secret resolved viaISecretProvider(defaultviegard-db-password), never configuration;AutoMigrateapplies migrations at host startup.EventPayload(BCL attributes only) for stable persisted payloads.IQueueStatsSource.GetStatsAsync(a sync stats call cannot be honestly implemented over a database);ChannelWorkQueuekeeps a sync core.Viegard:Persistence:Provider=inmemory(default, dev) orpostgres; startup migration when postgres.Fixes #
How was this tested?
dotnet build Viegard.slnx- 0 errors, 0 warningsdotnet test Viegard.slnx- 140/140 pass; 7 PostgreSQL integration tests written (enqueue/lease/complete, redelivery counts, dead-lettering, lease-expiry crash recovery, 5-consumer no-double-lease, LISTEN/NOTIFY wakeup, polymorphic store round-trip) currently skipped: gated onVIEGARD_TEST_POSTGRES, pending local Docker (WSL reboot) or the Debian VM (tracked in TODO.md)dotnet dotnet-efsucceedsChecklist
- Viegard.Persistence.Postgres: - ViegardDbContext + InitialSchema migration: raw observations, events (jsonb entities/payload), incidents, classifications, decisions, actions, audit records, corrections, queue telemetry, source offsets, queue messages + counters - Postgres store implementations for every persistence port, mapping immutable domain records to EF row types - PostgresWorkQueue: SKIP LOCKED visibility-timeout leases, delivery counting with dead-lettering enforced at lease time (crash-safe poison protection), LISTEN/NOTIFY wakeups with fallback poll, per-queue counters; PostgresCommandQueue for admin commands - DatabaseOptions (+ validator): password via ISecretProvider secret name, never configuration; AutoMigrate at host startup - Service registration extension + design-time factory for dotnet-ef - Domain: JSON polymorphism discriminators on EventPayload - Application: IQueueStatsSource.GetStatsAsync (durable queues compute stats in the database); ChannelWorkQueue keeps a sync core - PipelineHost: persistence provider switch (inmemory default, postgres via Viegard:Persistence:Provider) with startup migration - Tests: 140 passing + 7 PostgreSQL integration tests (queue round-trip, redelivery, dead-letter, lease expiry, concurrent consumers, LISTEN/NOTIFY wakeup, polymorphic store round-trip) gated on VIEGARD_TEST_POSTGRES pending local Docker (WSL reboot) - Deps (supply-chain reviewed): Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3, EF Core 10.0.11, recorded in THIRD-PARTY-NOTICES.md Verified: dotnet build (0 warnings), dotnet test (140/140 + 7 skips), host boots with default inmemory provider. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>