NSchema 2.1.0

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

NSchema

NSchema

NSchema is a declarative database schema migration library for .NET.

You describe the schema you want in C#. NSchema compares it against the current state of your database, then runs the SQL to bring it in line.

Designed to be familiar to .NET devs, with extensibility and safety features to support many different workflows.

Getting started

Install the core package and a database provider:

dotnet add package NSchema
dotnet add package NSchema.Postgres   # or another provider

Declare a schema by subclassing AbstractSchemaProvider:

using NSchema.Schema;
using NSchema.Schema.Fluent;

public class AppSchema : AbstractSchemaProvider
{
    public AppSchema()
    {
        Schema("app", s => s
            .Table("users", t => t
                .Column("id", SqlType.Text, c => c.PrimaryKey("users_pkey"))
                .Column("email", SqlType.Text, c => c.NotNull())
                .Column("name", SqlType.Text, c => c.NotNull())
                .Index("uc_users_email", ["email"], i => i.Unique())
            )
        );
    }
}

Wire up and run the application:

using NSchema;
using NSchema.Migration;
using NSchema.Postgres;

var builder = NSchemaApplication.CreateBuilder(args);

builder
    .AddSchema<AppSchema>()
    .UsePostgres(connectionString)
    .WithDestructiveActionPolicy(DestructiveActionPolicy.Warn);

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

On startup, NSchema introspects the database, compares it with your desired schema, and applies the resulting plan.

A run performs one of three operations:

  • Plan (default) computes the plan and renders it without touching the database.
  • Apply computes the plan and applies it.
  • Refresh captures the current live schema to the state store without planning or applying.

Call app.Plan() / app.Apply() / app.Refresh() explicitly, or configure the default via RunOperation(...) and use RunAsync(). See Configuration for details.

Documentation

  • Configuration. Hosting, operations, destructive-action policy, scoping, registering schemas, scripts, and policies.
  • Defining schemas. The full fluent reference for schemas, tables, columns, foreign keys, and indexes.
  • Concepts. The domain model, the pipeline, and how the pieces fit together.
  • Extension points. Every interface you can swap or extend, and how to register it.
  • Samples. Complete sample applications and reference implementations.
  • Roadmap. Planned features and improvements.

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 (3)

Showing the top 3 NuGet packages that depend on NSchema:

Package Downloads
NSchema.Postgres

PostgreSQL provider for NSchema

NSchema.Aws

AWS provider for NSchema

NSchema.Yaml

YAML provider for NSchema

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-alpha.1 0 6/3/2026
2.2.0-alpha2 43 6/2/2026
2.2.0-alpha.1 40 6/2/2026
2.1.0 64 6/1/2026
2.0.1 59 6/1/2026
2.0.0 72 6/1/2026
2.0.0-alpha.7 55 6/1/2026
2.0.0-alpha.6 68 5/31/2026
2.0.0-alpha.5 74 5/31/2026
2.0.0-alpha.4 65 5/30/2026
2.0.0-alpha.3 60 5/30/2026
2.0.0-alpha.2 64 5/30/2026
2.0.0-alpha.1 45 5/30/2026
1.0.1 100 5/27/2026
1.0.0 129 5/27/2026
1.0.0-rc.3 88 5/27/2026
1.0.0-rc.2 46 5/27/2026
1.0.0-rc.1 47 5/27/2026
Loading failed