Table of Contents

Interface IMigrationContext

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

The surface available to an IMigration while it runs. Everything here executes on the migration's own connection and transaction (DDL excepted — MySQL auto-commits it). Provides raw SQL helpers plus a bridge into the declarative schema sync so a migration can bring a table to its current model shape and then transform data in the same step.

public interface IMigrationContext

Properties

Connection

The migration's open connection.

MySqlConnection Connection { get; }

Property Value

MySqlConnection

Transaction

The migration's open transaction.

MySqlTransaction Transaction { get; }

Property Value

MySqlTransaction

Methods

ExecuteAsync(string, IReadOnlyDictionary<string, object?>?, CancellationToken)

Runs a non-query statement (INSERT/UPDATE/DELETE/DDL) and returns affected rows.

Task<int> ExecuteAsync(string sql, IReadOnlyDictionary<string, object?>? parameters = null, CancellationToken ct = default)

Parameters

sql string
parameters IReadOnlyDictionary<string, object>
ct CancellationToken

Returns

Task<int>

QueryAsync<T>(string, IReadOnlyDictionary<string, object?>?, CancellationToken)

Runs a query and materializes each row into T.

Task<List<T>> QueryAsync<T>(string sql, IReadOnlyDictionary<string, object?>? parameters = null, CancellationToken ct = default) where T : class, new()

Parameters

sql string
parameters IReadOnlyDictionary<string, object>
ct CancellationToken

Returns

Task<List<T>>

Type Parameters

T

ScalarAsync<T>(string, IReadOnlyDictionary<string, object?>?, CancellationToken)

Runs a query returning a single scalar (first column of the first row).

Task<T?> ScalarAsync<T>(string sql, IReadOnlyDictionary<string, object?>? parameters = null, CancellationToken ct = default)

Parameters

sql string
parameters IReadOnlyDictionary<string, object>
ct CancellationToken

Returns

Task<T>

Type Parameters

T

SyncTableAsync<T>(CancellationToken)

Brings the table for T to its current model shape via the schema analyzer (CREATE if missing, otherwise additive ALTERs). Lets a migration add only the data transform around it. Note: this issues DDL, which MySQL commits immediately.

Task SyncTableAsync<T>(CancellationToken ct = default) where T : class

Parameters

ct CancellationToken

Returns

Task

Type Parameters

T