Postgres¶
The Postgres package provides EF Core–backed implementations of Deepstaging runtime interfaces — replacing in-memory defaults with persistent PostgreSQL storage. One package reference swaps in production-grade persistence for data stores, background jobs, audit trails, and notifications.
Package: Deepstaging.Data.Postgres
Quick Start¶
builder.AddCatalogRuntime(options =>
{
options.AddPostgresCatalogStore(); // DataStore → EF Core
options.AddPostgresJobScheduler(); // Jobs → Postgres
options.AddPostgresAuditStore(); // Audit → Postgres
options.AddPostgresNotificationStore(); // Notifications → Postgres
});
No code changes to your domain — the same [DataStore], [StoredEntity], and effect pipelines work unchanged.
What Gets Generated¶
| Generated | Purpose |
|---|---|
Pg{Entity}Store |
EF Core implementation of I{Entity}Store per stored entity |
{DataStore}DbContext |
EF Core DbContext with DbSet<> for each entity |
{DataStore}ModelBuilderExtensions |
ApplyPostgresConfigurations() for BYOC |
AddPostgres{DataStore}() |
DI registration extension method |
Infrastructure Services¶
| Interface | Implementation | Registration | Schema |
|---|---|---|---|
IAuditStore |
PgAuditStore<TContext> |
AddPostgresAuditStore() |
ds_audit |
IJobScheduler |
PgJobScheduler<TContext> |
AddPostgresJobScheduler() |
ds_jobs |
IJobStore |
PgJobStore<TContext> |
AddPostgresJobStore() |
ds_jobs |
INotificationStore |
PgNotificationStore<TContext> |
AddPostgresNotificationStore() |
ds_notify |
INotificationChannel |
PgNotificationChannel<TContext> |
AddPostgresNotificationChannel() |
ds_notify |
TypedId Converter Requirement¶
TypedId properties on [StoredEntity] types must include IdConverters.EfCoreValueConverter:
[TypedId(Converters = IdConverters.JsonConverter | IdConverters.EfCoreValueConverter)]
public readonly partial struct CatalogItemId;
The DSPG01 analyzer enforces this at compile time.
BYOC (Bring Your Own Context)¶
If you have an existing DbContext, apply Deepstaging configurations to it:
public class AppDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyDeepstagingConfigurations();
}
}
// Register against your context
options.AddPostgresAuditStore<AppRuntime, AppDbContext>();
Migrations¶
The generator produces IDesignTimeDbContextFactory<T> for CLI support. Create migrations with:
Development: Pending migrations are applied automatically on startup via DeepstagingSchemaService.
Production: Pending migrations cause a fail-fast DeepstagingSchemaMismatchException — apply before deploying:
dotnet ef migrations script --idempotent --context CatalogStoreDbContext -o migrate.sql
psql -h $DB_HOST -d $DB_NAME -f migrate.sql
Diagnostics¶
| ID | Severity | Description | Code Fix |
|---|---|---|---|
| DSPG01 | Error | TypedId used by [StoredEntity] must include IdConverters.EfCoreValueConverter |
Adds the converter flag |
| DSPG02 | Warning | [DataStore] has a generated DbContext but no migrations |
— |