EnvelopeFlow.Audiences.Stores.Postgres
0.1.0-alpha.3.1
dotnet add package EnvelopeFlow.Audiences.Stores.Postgres --version 0.1.0-alpha.3.1
NuGet\Install-Package EnvelopeFlow.Audiences.Stores.Postgres -Version 0.1.0-alpha.3.1
<PackageReference Include="EnvelopeFlow.Audiences.Stores.Postgres" Version="0.1.0-alpha.3.1" />
<PackageVersion Include="EnvelopeFlow.Audiences.Stores.Postgres" Version="0.1.0-alpha.3.1" />
<PackageReference Include="EnvelopeFlow.Audiences.Stores.Postgres" />
paket add EnvelopeFlow.Audiences.Stores.Postgres --version 0.1.0-alpha.3.1
#r "nuget: EnvelopeFlow.Audiences.Stores.Postgres, 0.1.0-alpha.3.1"
#:package EnvelopeFlow.Audiences.Stores.Postgres@0.1.0-alpha.3.1
#addin nuget:?package=EnvelopeFlow.Audiences.Stores.Postgres&version=0.1.0-alpha.3.1&prerelease
#tool nuget:?package=EnvelopeFlow.Audiences.Stores.Postgres&version=0.1.0-alpha.3.1&prerelease
Optional PostgreSQL audiences and snapshots
This feature exposes an immutable Postgres*Migration*.Catalog for explicit schema inspection/planning/adoption with an application-owned PostgresMigrationRunner. See upgrade operations. Existing initializers stay explicit; construction and worker startup never apply migrations. Select only the installed feature catalog, independently from conversation/history storage.
PostgresAudienceStore implements IAudienceListStore, IAudienceResolver and the optional IAudienceSnapshotRetentionStore. Applications can continue using their own audience tables/resolvers. This package adds no endpoints, authentication, user entities, provider selection or conversation/history dependency. List membership never grants permission to send.
Create the store with an application-owned NpgsqlDataSource and call InitializeAsync explicitly during deployment/migration. Construction does not connect or initialize a schema. Initialization is additive and coordinated across clients, rather than a versioned upgrade system. The application owns connection lifetime, authorization, retention scheduling and database protections.
await using var data = NpgsqlDataSource.Create(applicationConnectionString);
var audiences = new PostgresAudienceStore(data, new()
{
MaximumRecipients = 100_000,
SnapshotLifetime = TimeSpan.FromHours(1),
});
await audiences.InitializeAsync();
await audiences.ReplaceAsync(authorizedScope, "weekly-updates", applicationRecipientIds);
var snapshot = await audiences.BeginSnapshotAsync(authorizedScope, "weekly-updates");
var page = await audiences.ReadPageAsync(authorizedScope, new(snapshot.SnapshotId, 0), 100);
Imports validate identifiers and bound inspected input items, including duplicates, before database mutation. The configurable limit is 1–1,000,000 items, default 100,000. Membership is deduplicated and sorted using .NET ordinal string ordering. A transaction locks the list header, replaces its membership using binary COPY, and advances its revision/count together. Failure or cancellation rolls back the complete replacement. Memory during import is bounded by the configured input limit; caller-owned enumerable execution must itself be responsive.
Snapshot creation takes a shared list-header lock and copies committed membership server-side into immutable ordinal rows. Its count and membership commit atomically, so a simultaneous replacement cannot produce a mixed snapshot. Each snapshot records its source list revision and absolute expiry. Updating the list or constructing another adapter with different lifetime options cannot change an existing snapshot.
Pages contain 1–1000 recipients, selected through the (scope_key,snapshot_id,ordinal) index with an ordinal range, rather than an SQL OFFSET scan or an entire audience read. A page validates contiguous ordinals and the declared count, failing explicitly for inconsistent storage. Its shared snapshot-header lock prevents retention from deleting rows mid-page. An offset equal to the count returns an empty terminal page; an offset beyond the count fails. Missing, expired and wrong-scope checkpoints use the same non-disclosing failure.
PostgreSQL time determines creation and expiration for all clients. Lifetimes must be positive and at most seven days; sub-microsecond precision rounds up to PostgreSQL's timestamp precision. SHA-256 scope/list index keys keep indexes bounded for maximum-length Unicode identifiers. Exact scope dimensions and list identifiers are verified alongside those keys; a conflicting scope/list digest fails safely rather than replacing another audience. These hashes are indexing aids, not anonymization of recipient IDs stored in the database.
Call PurgeExpiredSnapshotsAsync(authorizedScope, limit) explicitly to remove at most 1–1000 expired snapshot headers and their membership rows. It uses scoped, ordered SKIP LOCKED selection and never removes list membership or unexpired snapshots. The return value counts deleted snapshots. Cascading work scales with membership in the selected snapshots; choose a small batch for large audiences. Total database growth remains an application retention/capacity decision. No constructor, import, snapshot operation or worker automatically runs cleanup.
Durable campaign recovery requires this persisted snapshot (or an application-owned equivalent), durable campaign checkpoints and an atomic idempotent admission sink. Snapshot membership must remain valid through the campaign's declared expiry. Consent and destination ownership are checked independently before submission. This store makes no provider-delivery claim.
Run focused tests against a disposable PostgreSQL database:
ENVELOPEFLOW_TEST_POSTGRES='Host=localhost;Database=envelopeflow_tests;Username=envelopeflow;Password=local-only' \
dotnet test tests/Audiences/EnvelopeFlow.Audiences.Stores.Postgres.Tests --configuration Release
The tests exercise reusable audience assertions, complete scope isolation, immutable pages, concurrent replacement/snapshot creation, actual COPY rollback, database-clock expiry, bounded explicit retention, long Unicode identifiers and a 10,000-member indexed deep page. A bounded task-owned .NET child process reads a persisted checkpoint after the source list changes; this proves process-independent snapshot recovery, without claiming database failover or a production capacity ceiling. Missing database configuration is inconclusive; record actual passed/skipped counts when reporting verification.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- EnvelopeFlow.Audiences (>= 0.1.0-alpha.3.1)
- EnvelopeFlow.Stores.Migrations.Postgres (>= 0.1.0-alpha.3.1)
- Npgsql (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-alpha.3.1 | 44 | 11/22/2026 |
| 0.1.0-alpha.2.1 | 58 | 11/9/2026 |