Lyo.Postgres 1.0.1

dotnet add package Lyo.Postgres --version 1.0.1
                    
NuGet\Install-Package Lyo.Postgres -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lyo.Postgres" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.Postgres" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Lyo.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lyo.Postgres --version 1.0.1
                    
#r "nuget: Lyo.Postgres, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lyo.Postgres@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lyo.Postgres&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.Postgres&version=1.0.1
                    
Install as a Cake Tool

Lyo.Postgres

Shared PostgreSQL migration plumbing for Lyo libraries that ship their own EF Core schema (Audit, Email, ChangeTracker, EntityReference, etc.). The package is a thin IHostedService that runs DbContext.Database.MigrateAsync at host startup when the consumer’s options opt in.

Out of scope: this package does not ship health checks, design-time IDesignTimeDbContextFactory helpers, or connection-string builders. Those live in the consumer > libraries (e.g. Lyo.Audit.Postgres, Lyo.Email.Postgres) when needed.

Examples

Usage

using Lyo.Postgres;
using Microsoft.Extensions.DependencyInjection;

public sealed class AuditDbOptions : IPostgresMigrationConfig
{
    public string ConnectionString { get; init; } = "";
    public bool EnableAutoMigrations { get; init; }
    public string Schema { get; init; } = "audit";
}

services.Configure<AuditDbOptions>(configuration.GetSection("Audit:Postgres"));
services.AddPostgresMigrations<AuditDbContext, AuditDbOptions>();

Public API

Type Role
IPostgresMigrationConfig Contract for options classes that want to opt into hosted migrations. Members: string ConnectionString, bool EnableAutoMigrations, string Schema.
PostgresMigrationHostedService<TContext, TOptions> IHostedService that, on StartAsync, scopes a fresh TContext over the configured connection string, runs CREATE SCHEMA IF NOT EXISTS "<Schema>", then MigrateAsync.
Extensions.AddPostgresMigrations<TContext, TOptions>() Registers the hosted service. Both type parameters are constrained: TContext : DbContext, TOptions : class, IPostgresMigrationConfig.

The hosted service activates a TContext instance via Activator.CreateInstance(typeof(TContext), dbContextOptions), so each consumer DbContext must expose a public constructor that takes a single DbContextOptions<TContext>. The migrations history table is stored in the schema returned by IPostgresMigrationConfig.Schema as "<schema>"."__EFMigrationsHistory".

StartAsync short-circuits when EnableAutoMigrations is false. If the flag is true, both ConnectionString and Schema are required (whitespace throws via Lyo.Exceptions.ArgumentHelpers).

Usage

  • The hosted service resolves IOptions<AuditDbOptions>.
  • If EnableAutoMigrations is false, it returns immediately.
  • Otherwise it constructs an AuditDbContext with UseNpgsql(connectionString, opt => opt.MigrationsHistoryTable("__EFMigrationsHistory", schema)).
  • It executes CREATE SCHEMA IF NOT EXISTS "<schema>" (the schema name is escaped by doubling embedded " characters before interpolation).
  • It runs Database.MigrateAsync(ct).

Consumers

  • Lyo.Audit.Postgres
  • Lyo.Email.Postgres
  • Lyo.ChangeTracker.Postgres
  • Lyo.EntityReference.Postgres
  • Lyo.FileMetadataStore.Postgres

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Exceptions — (direct, lyo)
  • Microsoft.EntityFrameworkCore 10.0.5 — (direct, microsoft)
  • Microsoft.EntityFrameworkCore.Design 10.0.5 — (direct, microsoft)
  • Microsoft.EntityFrameworkCore.Relational 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.Options 10.0.5 — (direct, microsoft)
  • Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 — (direct, third-party)
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (26)

Showing the top 5 NuGet packages that depend on Lyo.Postgres:

Package Downloads
Lyo.EntityReference.Postgres

Entity Framework Core base entity, configuration, and store helpers for canonical entity-ref rows on PostgreSQL.

Lyo.Sms.Postgres

PostgreSQL implementation of Lyo.Sms using Entity Framework Core.

Lyo.Email.Postgres

PostgreSQL schema and entities for email logging. Consumers map EmailSent events and insert into email_logs / email_attachment_logs.

Lyo.Reporting.Postgres

PostgreSQL reporting data layer with EF Core, optional auto-migrations, and report generation orchestration.

Lyo.HomeInventory.Postgres

PostgreSQL storage for Lyo.HomeInventory (EF Core): household items, rooms/locations, quantities, and change history.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 40 8/18/2026
1.0.0 169 8/16/2026