Class MigrationRunner
Discovers, orders, and runs IMigration instances on top of the
MigrationTracker's __migrations history. Migrations are applied in
MigrationVersion order, each in its own transaction, gated by the app version and
serialized across nodes by the shared SchemaSyncLock.
public sealed class MigrationRunner
- Inheritance
-
MigrationRunner
- Inherited Members
Constructors
MigrationRunner(ConnectionManager, MigrationTracker, ILogger?)
public MigrationRunner(ConnectionManager connectionManager, MigrationTracker tracker, ILogger? logger = null)
Parameters
connectionManagerConnectionManagertrackerMigrationTrackerloggerILogger
Methods
GetPendingAsync(string, CancellationToken)
Returns the migrations that are pending (registered, at or below the current app version, and not yet applied) in apply order — without applying anything.
public Task<IReadOnlyList<MigrationPlanItem>> GetPendingAsync(string connectionId = "Default", CancellationToken ct = default)
Parameters
connectionIdstringctCancellationToken
Returns
MigrateAsync(string, CancellationToken)
Applies all pending migrations in order, each in its own transaction, under the shared schema-sync lock. Also warns when a previously-applied migration's checksum has drifted.
public Task<Result<MigrationRunResult>> MigrateAsync(string connectionId = "Default", CancellationToken ct = default)
Parameters
connectionIdstringctCancellationToken
Returns
- Task<Result<MigrationRunResult>>
Register(IMigration)
Registers a migration instance for discovery.
public MigrationRunner Register(IMigration migration)
Parameters
migrationIMigration
Returns
RegisterFrom(Assembly)
Registers every concrete IMigration with a public parameterless constructor
found in assembly.
public MigrationRunner RegisterFrom(Assembly assembly)
Parameters
assemblyAssembly
Returns
RollbackAsync(MigrationVersion, string, CancellationToken)
Rolls back every applied migration whose version is strictly greater than
target, newest-first, each in its own transaction. Aborts before making
any change if a migration in range does not support DownAsync.
public Task<Result<MigrationRunResult>> RollbackAsync(MigrationVersion target, string connectionId = "Default", CancellationToken ct = default)
Parameters
targetMigrationVersionconnectionIdstringctCancellationToken
Returns
- Task<Result<MigrationRunResult>>