Table of Contents

Class MigrationRunner

Namespace
CL.MySQL2.Services
Assembly
CL.MySQL2.dll

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

connectionManager ConnectionManager
tracker MigrationTracker
logger ILogger

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

connectionId string
ct CancellationToken

Returns

Task<IReadOnlyList<MigrationPlanItem>>

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

connectionId string
ct CancellationToken

Returns

Task<Result<MigrationRunResult>>

Register(IMigration)

Registers a migration instance for discovery.

public MigrationRunner Register(IMigration migration)

Parameters

migration IMigration

Returns

MigrationRunner

RegisterFrom(Assembly)

Registers every concrete IMigration with a public parameterless constructor found in assembly.

public MigrationRunner RegisterFrom(Assembly assembly)

Parameters

assembly Assembly

Returns

MigrationRunner

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

target MigrationVersion
connectionId string
ct CancellationToken

Returns

Task<Result<MigrationRunResult>>