Choose a runner
Use the same migration assembly in a dedicated host, a DI scope or the command-line tool.
Examples use Classic and Fluent tabs. Your choice follows you through the manual.
Execution choices
| Runner | A good fit |
|---|---|
| Library host | A small deployment executable with explicit connection ownership and full provider access. |
| Microsoft DI integration | A service collection supplying constructor dependencies, options and logging. |
| migrator CLI | Automation that selects assemblies, providers, scopes, tags and target versions. |
A dedicated host
Run schema changes before application instances need the new schema. The host below works with either migration style and scans the assembly containing CreateUsers. Use explicit type selection when an assembly also contains migrations for other purposes.
Classic
using DotNetProjects.Migrator;
using DotNetProjects.Migrator.Providers;
using Microsoft.Data.Sqlite;
using var connection = new SqliteConnection("Data Source=app.db");
connection.Open();
using var provider = ProviderFactory.Create(
ProviderTypes.SQLite, connection, defaultSchema: null);
var runner = new Migrator(provider, typeof(CreateUsers).Assembly, trace: false);
runner.MigrateToLastVersion();Fluent
using DotNetProjects.Migrator;
using DotNetProjects.Migrator.Providers;
using Microsoft.Data.Sqlite;
using var connection = new SqliteConnection("Data Source=app.db");
connection.Open();
using var provider = ProviderFactory.Create(
ProviderTypes.SQLite, connection, defaultSchema: null);
var runner = new Migrator(provider, typeof(CreateUsers).Assembly, trace: false);
runner.MigrateToLastVersion();Shared host · both styles
Deployment responsibilities
Give the deployment identity the schema privileges needed by the selected migrations. Coordinate concurrent deploys through an external orchestrator or supported native lock. Configure the history table and scope consistently across invocations. Log the target and result without exposing connection strings.
Choose the CLI for a ready command surface, or DI for application services. Read transaction and lock semantics before relying on atomicity.