Skip to content

DmMigrator ​

Namespace: MJCZone.DapperMatic.Migrations

Assembly: MJCZone.DapperMatic

Summary ​

Keeps a database's tables in line with their models, reconciling only the tables whose model changed since they were last reconciled.

sealed public

Contents ​

Constructors (1) | Methods (11) | Properties (2)

Constructors ​

DmMigrator ​

Initializes a new instance of the DmMigrator class.

csharp
DmMigrator(DmMigrationOptions options)

Parameters ​

Methods ​

MethodSummary
AddTableRegisters the table a class describes.
AddTableRegisters the table a class describes.
AddTableRegisters a table model.
AddTablesFromAssemblyRegisters every class in an assembly marked with DmTableAttribute....
GetPlanAsyncWorks out which tables a run would reconcile, from the ledger and the models alone. Nothing is chang...
MigrateAsyncReconciles every registered table whose model changed since it was last reconciled, and records the ...
MigrateSchemasAsyncMigrates the registered models into several schemas: the models DmSchemaLayout declares shared onc...
GetType
ToString
Equals
GetHashCode

AddTable ​

Registers the table a class describes.

csharp
DmMigrator AddTable()

Returns ​

Type: DmMigrator

This migrator.

AddTable ​

Registers the table a class describes.

csharp
DmMigrator AddTable(Type type)

Parameters ​

  • type (Type) - reads it.

Returns ​

Type: DmMigrator

This migrator.

AddTable ​

Registers a table model.

csharp
DmMigrator AddTable(DmTable table)

Parameters ​

Returns ​

Type: DmMigrator

This migrator.

AddTablesFromAssembly ​

Registers every class in an assembly marked with DmTableAttribute.

csharp
DmMigrator AddTablesFromAssembly(Assembly assembly, Type predicate)

Parameters ​

  • assembly (Assembly) - The assembly.
  • predicate (Type) - Which of those classes to register, such as the ones in one namespace when an assembly holds the models of more than one database. Null registers them all.

Returns ​

Type: DmMigrator

This migrator.

GetPlanAsync ​

Works out which tables a run would reconcile, from the ledger and the models alone. Nothing is changed and no lock is taken.

csharp
Task<DmMigrationPlan> GetPlanAsync(
    IDbConnection db,
    CancellationToken cancellationToken)

Parameters ​

  • db (IDbConnection) - The database connection. It is opened if it is closed, and closed again afterwards.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task<DmMigrationPlan>

The plan.

MigrateAsync ​

Reconciles every registered table whose model changed since it was last reconciled, and records the new fingerprints.

csharp
Task&lt;DmMigrationResult&gt; MigrateAsync(
    IDbConnection db,
    bool force,
    CancellationToken cancellationToken)

Parameters ​

  • db (IDbConnection) - The database connection, with no transaction open on it. It is opened if it is closed, and closed again afterwards.
  • force (bool) - True to reconcile every table whatever was recorded: the way to repair a table changed by hand, which a fingerprint of the model cannot notice. A forced run also reconciles models a rename superseded, so run it from the current version of the application.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task<DmMigrationResult>

What the run did.

MigrateSchemasAsync ​

Migrates the registered models into several schemas: the models DmSchemaLayout declares shared once, into the shared schema, and every other model into each schema listed.

csharp
Task&lt;DmSchemaMigrationResult&gt; MigrateSchemasAsync(
    IDbConnection} connectionFactory,
    String} schemas,
    int maxParallelism,
    bool force,
    CancellationToken cancellationToken)

Parameters ​

  • connectionFactory (IDbConnection}) - Makes a connection for a schema's run, which the run opens and disposes.

  • schemas (String}) - The schemas, such as every tenant's from a registry; the shared schema may be one of them, for the tenant that shares it. A schema that does not exist is created.

  • maxParallelism (int) - The most schemas migrated at once, after the shared schema.

  • force (bool) - .

  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task<DmSchemaMigrationResult>

Each schema's outcome. A schema that fails does not stop the others; nothing of its run is recorded.

GetType ​

csharp
GetType()

ToString ​

csharp
ToString()

Equals ​

csharp
Equals()

GetHashCode ​

csharp
GetHashCode()

Properties ​

Options ​

Gets the options.

Type: DmMigrationOptions

Tables ​

Gets the registered table models, in the order registered.

Type: IReadOnlyList<DmTable>