Skip to content

MigrationRunner

Namespace AgentPrism · Assembly AgentPrism.SqlServer.dll, AgentPrism.PostgreSql.dll, AgentPrism.Sqlite.dll

Applies the embedded SQL migrations to the database.

public sealed class MigrationRunner : ISqlPersistenceDiagnostics

objectMigrationRunner

ISqlPersistenceDiagnostics

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

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.

Gets the provider name, for example PostgreSQL.

public string ProviderName { get; }

string

Applies pending migrations.

public ValueTask<int> ApplyAsync(CancellationToken cancellationToken = default)

cancellationToken CancellationToken

The cancellation token.

ValueTask<int>

The number of applied migrations. 0 if everything is current.

AgentPrismException

An applied migration file has been modified (checksum mismatch), an unknown migration set is enabled, or an error occurred while running a migration.

Reads the connection and migration status WITHOUT applying any migration.

public ValueTask<SqlPersistenceDiagnosticsSnapshot> GetSnapshotAsync(CancellationToken cancellationToken = default)

cancellationToken CancellationToken

The cancellation token.

ValueTask<SqlPersistenceDiagnosticsSnapshot>

CanConnect: false if the connection could not be established; otherwise the list of pending migrations.