Switchknife.Migrations
0.1.0
dotnet add package Switchknife.Migrations --version 0.1.0
NuGet\Install-Package Switchknife.Migrations -Version 0.1.0
<PackageReference Include="Switchknife.Migrations" Version="0.1.0" />
<PackageVersion Include="Switchknife.Migrations" Version="0.1.0" />
<PackageReference Include="Switchknife.Migrations" />
paket add Switchknife.Migrations --version 0.1.0
#r "nuget: Switchknife.Migrations, 0.1.0"
#:package Switchknife.Migrations@0.1.0
#addin nuget:?package=Switchknife.Migrations&version=0.1.0
#tool nuget:?package=Switchknife.Migrations&version=0.1.0
Switchknife.Migrations
Applies the SQL scripts embedded in an assembly to PostgreSQL with DbUp: in name order, each once, journalled in the database's schemaversions table. Run it on start, before anything reads the schema.
<EmbeddedResource Include="../../db/migrations/*.sql" LinkBase="Migrations" />
var migrator = new DatabaseMigrator(connectionString, typeof(Program).Assembly, logger);
migrator.Run(); // creates the database when missing, runs what is new, returns the names it ran
What Run does:
- Creates the database when it does not exist. That check connects to the server's maintenance database without pooling, so starting many hosts against one server (tests) does not leave an idle connection per start.
- Runs every embedded script whose resource name passes
ScriptFilterand is not journalled yet, ordered by name, each in its own transaction. - Logs one line,
Database schema is up to date ({Applied} script(s) applied)., and returns the applied names.
A failed script throws InvalidOperationException: the message names the script, the inner exception is the database error (PostgresException). With a transaction per script, the failed script leaves nothing behind and is not journalled; scripts before it stay applied.
Options (MigrationOptions, all optional):
| Option | Default | Use |
|---|---|---|
ScriptFilter |
name contains .Migrations. |
Pick another folder, or migrate only up to a script (a test that builds an older schema). |
Transaction |
PerScript |
None for statements PostgreSQL refuses inside a transaction: create index concurrently, TimescaleDB continuous aggregates. A script then fails part-way with its earlier statements applied, so write each one to run again safely (if not exists, create or replace). |
DbUpInformationLevel |
Information |
The level of DbUp's information lines (each script run, journal checks). Debug keeps a routine start to the one summary line. |
Logging: DbUp's trace, debug, information, warning and error lines go to the ILogger you pass at the same level (information at DbUpInformationLevel). Each line is formatted by DbUp's composite format with the invariant culture and logged under the constant template {Message}, so it reads exactly as DbUp wrote it.
Native AOT: works. samples/Switchknife.AotSmoke publishes with Native AOT, warnings as errors, and migrates a real PostgreSQL database (create, two scripts, a second run with nothing to do, DbUp's lines through the logger). DbUp and Npgsql carry no trimming annotations of their own; the publish reports no trim or AOT warning for the paths this package uses. Scripts are read with Assembly.GetManifestResourceStream, which the AOT compiler keeps.
Limits:
- PostgreSQL only, scripts embedded in one assembly. Script variables, code scripts and other journals are DbUp features this package does not expose.
- No down migrations, no locking between processes: run one migrator per database at a time (on start of the single instance, or as a step before the others start).
- Synchronous, as DbUp is.
| Product | Versions 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. |
-
net10.0
- dbup-postgresql (>= 7.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- 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 | 39 | 10/14/2026 |