Class MongoMigrationHistory
Tracks applied migrations in a dedicated MongoDB collection (_migrations by default), keyed by the
migration's stable Id. The collection makes migration state visible and
queryable like any other data.
public sealed class MongoMigrationHistory : IMigrationHistory
- Inheritance
-
MongoMigrationHistory
- Implements
- Inherited Members
Constructors
MongoMigrationHistory(IMongoDatabase, string?)
Initializes the history over a database.
public MongoMigrationHistory(IMongoDatabase database, string? collectionName = null)
Parameters
databaseIMongoDatabaseThe database.
collectionNamestringThe history collection name; defaults to DefaultCollectionName.
Fields
DefaultCollectionName
The default history collection name.
public const string DefaultCollectionName = "_migrations"
Field Value
Methods
EnsureCreatedAsync(CancellationToken)
Ensures the backing store for the history exists (idempotent). Called before the first read/record.
public Task EnsureCreatedAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token.
Returns
GetAppliedIdsAsync(CancellationToken)
Gets the identifiers of the migrations already applied.
public Task<IReadOnlyCollection<string>> GetAppliedIdsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token.
Returns
RecordAsync(AppliedMigration, CancellationToken)
Records a migration as applied.
public Task RecordAsync(AppliedMigration migration, CancellationToken cancellationToken = default)
Parameters
migrationAppliedMigrationThe applied migration.
cancellationTokenCancellationTokenThe cancellation token.