Table of Contents

Class MongoMigrationHistory

Namespace
eQuantic.Core.Data.MongoDb.Migration
Assembly
eQuantic.Core.Data.MongoDb.dll

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

database IMongoDatabase

The database.

collectionName string

The history collection name; defaults to DefaultCollectionName.

Fields

DefaultCollectionName

The default history collection name.

public const string DefaultCollectionName = "_migrations"

Field Value

string

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

cancellationToken CancellationToken

The cancellation token.

Returns

Task

GetAppliedIdsAsync(CancellationToken)

Gets the identifiers of the migrations already applied.

public Task<IReadOnlyCollection<string>> GetAppliedIdsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IReadOnlyCollection<string>>

RecordAsync(AppliedMigration, CancellationToken)

Records a migration as applied.

public Task RecordAsync(AppliedMigration migration, CancellationToken cancellationToken = default)

Parameters

migration AppliedMigration

The applied migration.

cancellationToken CancellationToken

The cancellation token.

Returns

Task