NSchema.Postgres 2.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package NSchema.Postgres --version 2.0.0
                    
NuGet\Install-Package NSchema.Postgres -Version 2.0.0
                    
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="NSchema.Postgres" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NSchema.Postgres" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NSchema.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 NSchema.Postgres --version 2.0.0
                    
#r "nuget: NSchema.Postgres, 2.0.0"
                    
#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 NSchema.Postgres@2.0.0
                    
#: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=NSchema.Postgres&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NSchema.Postgres&version=2.0.0
                    
Install as a Cake Tool

NSchema.Postgres

PostgreSQL provider for NSchema, the declarative database schema migration library for .NET.

This package plugs PostgreSQL-specific implementations of NSchema's ISchemaProvider (live-database introspection) and ISqlPlanner (DDL generation) into your application, and contributes Postgres-only SqlType helpers.

Getting started

Install the core package and this provider:

dotnet add package NSchema
dotnet add package NSchema.Postgres

Register Postgres against an NSchemaApplicationBuilder:

using NSchema;
using NSchema.Postgres;

var builder = NSchemaApplication.CreateBuilder(args);

builder
    .AddSchemasFromAssemblyContaining<Program>()
    .UseCurrentSchemaPostgres(connectionString);

var app = builder.Build();
await app.Apply();

On startup NSchema introspects the database through this provider, diffs it against your declared schema, and applies the resulting plan.

Configuration

UseCurrentSchemaPostgres has four overloads. The three connection-aware overloads register an NpgsqlDataSource for you (via AddNpgsqlDataSource) and wire up the current schema provider and SQL planner; the no-arg overload assumes you've already registered an NpgsqlDataSource yourself.

// 1. Connection string.
builder.UseCurrentSchemaPostgres("Host=localhost;Database=app;Username=postgres;Password=postgres");

// 2. Configure the data source builder directly.
builder.UseCurrentSchemaPostgres(b => b
    .EnableDynamicJson()
    .UseLoggerFactory(loggerFactory)
);

// 3. As above, with access to the IServiceProvider.
builder.UseCurrentSchemaPostgres((sp, b) => b.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>()));

// 4. Bring your own data source.
builder.Services.AddNpgsqlDataSource(connectionString);
builder.UseCurrentSchemaPostgres();

Postgres-specific types

SqlTypePostgresExtensions adds Postgres-only members to SqlType:

Member Postgres type Notes
SqlType.Citext citext Case-insensitive text. Requires the citext extension.
SqlType.Jsonb jsonb Binary JSON.
users.Column("email", SqlType.Citext).NotNull();
users.Column("metadata", SqlType.Jsonb);

citext requires CREATE EXTENSION citext; in the target database — NSchema.Postgres does not create extensions for you.

Supported schema objects

The introspector reads, and the planner emits DDL for:

  • Schemas (including comments and GRANTs on the schema itself)
  • Tables (including comments and table-level GRANTs)
  • Columns (types, nullability, defaults, comments)
  • Primary keys
  • Foreign keys
  • Indexes, including unique indexes and index comments

Requirements

  • .NET 10
  • PostgreSQL (tested against postgres:17-alpine via Testcontainers)

License

See LICENSE.

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

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
3.0.0-alpha.1 0 6/4/2026
2.0.0 85 6/1/2026
2.0.0-alpha.2 65 5/31/2026
2.0.0-alpha.1 68 5/30/2026
1.0.0 109 5/27/2026
1.0.0-rc.1 92 5/27/2026