MigrationRunner
AgentPrism.SqlServer.dll, AgentPrism.PostgreSql.dll, AgentPrism.Sqlite.dllApplies the embedded SQL migrations to the database.
public sealed class MigrationRunner : ISqlPersistenceDiagnosticsInheritance
Section titled “Inheritance”Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”The runner uses one coordination scope per configured database namespace:
| Provider | Namespace | Migration lock |
|---|---|---|
| PostgreSQL | Schema | pg_advisory_lock on one connection |
| SQL Server | Schema | sp_getapplock on one connection |
| SQLite | Table prefix | Sidecar file lock next to the database |
It creates the namespace and __migrations ledger when needed, verifies the
SHA-256 checksum of every applied file, and applies each pending migration in its
own transaction. A checksum mismatch fails instead of running against an unknown
schema state.
Some migrations create database-wide objects. PostgreSQL’s pgvector extension is one example. Concurrent first-time migration of different schemas can race on that shared object; the guarded operation is retried safely.
Properties
Section titled “Properties”ProviderName
Section titled “ ProviderName”Gets the provider name, for example PostgreSQL.
public string ProviderName { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”ApplyAsync(CancellationToken)
Section titled “ ApplyAsync(CancellationToken)”Applies pending migrations.
public ValueTask<int> ApplyAsync(CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”The number of applied migrations. 0 if everything is current.
Exceptions
Section titled “Exceptions”An applied migration file has been modified (checksum mismatch), an unknown migration set is enabled, or an error occurred while running a migration.
GetSnapshotAsync(CancellationToken)
Section titled “ GetSnapshotAsync(CancellationToken)”Reads the connection and migration status WITHOUT applying any migration.
public ValueTask<SqlPersistenceDiagnosticsSnapshot> GetSnapshotAsync(CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<SqlPersistenceDiagnosticsSnapshot>
CanConnect: false if the connection could not be established; otherwise the list of pending migrations.