Table of Contents

Interface IHistoryRepository

Namespace
Microsoft.EntityFrameworkCore.Migrations
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

An interface for the repository used to access the '__EFMigrationsHistory' table that tracks metadata about EF Core Migrations such as which migrations have been applied.

Database providers typically implement this service by inheriting from HistoryRepository.

The service lifetime is Scoped. This means that each Microsoft.EntityFrameworkCore.DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.

public interface IHistoryRepository

Methods

Exists()

Checks whether or not the history table exists.

bool Exists()

Returns

bool

true if the table already exists, false otherwise.

ExistsAsync(CancellationToken)

Checks whether or not the history table exists.

Task<bool> ExistsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if the table already exists, false otherwise.

GetAppliedMigrations()

Queries the history table for all migrations that have been applied.

IReadOnlyList<HistoryRow> GetAppliedMigrations()

Returns

IReadOnlyList<HistoryRow>

The list of applied migrations, as HistoryRow entities.

GetAppliedMigrationsAsync(CancellationToken)

Queries the history table for all migrations that have been applied.

Task<IReadOnlyList<HistoryRow>> GetAppliedMigrationsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<IReadOnlyList<HistoryRow>>

A task that represents the asynchronous operation. The task result contains the list of applied migrations, as HistoryRow entities.

GetBeginIfExistsScript(string)

Generates a SQL Script that will BEGIN a block of SQL if and only if the migration with the given identifier already exists in the history table.

string GetBeginIfExistsScript(string migrationId)

Parameters

migrationId string

The migration identifier.

Returns

string

The generated SQL.

GetBeginIfNotExistsScript(string)

Generates a SQL Script that will BEGIN a block of SQL if and only if the migration with the given identifier does not already exist in the history table.

string GetBeginIfNotExistsScript(string migrationId)

Parameters

migrationId string

The migration identifier.

Returns

string

The generated SQL.

GetCreateIfNotExistsScript()

Generates a SQL script that will create the history table if and only if it does not already exist.

string GetCreateIfNotExistsScript()

Returns

string

The SQL script.

GetCreateScript()

Generates a SQL script that will create the history table.

string GetCreateScript()

Returns

string

The SQL script.

GetDeleteScript(string)

Generates a SQL script to delete a row from the history table.

string GetDeleteScript(string migrationId)

Parameters

migrationId string

The migration identifier of the row to delete.

Returns

string

The generated SQL.

GetEndIfScript()

Generates a SQL script to END the SQL block.

string GetEndIfScript()

Returns

string

The generated SQL.

GetInsertScript(HistoryRow)

Generates a SQL script to insert a row into the history table.

string GetInsertScript(HistoryRow row)

Parameters

row HistoryRow

The row to insert, represented as a HistoryRow entity.

Returns

string

The generated SQL.