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.
DmMigrator(DmMigrationOptions options)Parameters
- options (DmMigrationOptions) - The options, or null for the defaults.
Methods
| Method | Summary |
|---|---|
| AddTable | Registers the table a class describes. |
| AddTable | Registers the table a class describes. |
| AddTable | Registers a table model. |
| AddTablesFromAssembly | Registers every class in an assembly marked with DmTableAttribute.... |
| GetPlanAsync | Works out which tables a run would reconcile, from the ledger and the models alone. Nothing is chang... |
| MigrateAsync | Reconciles every registered table whose model changed since it was last reconciled, and records the ... |
| MigrateSchemasAsync | Migrates the registered models into several schemas: the models DmSchemaLayout declares shared onc... |
| GetType | |
| ToString | |
| Equals | |
| GetHashCode |
AddTable
Registers the table a class describes.
DmMigrator AddTable()Returns
Type: DmMigrator
This migrator.
AddTable
Registers the table a class describes.
DmMigrator AddTable(Type type)Parameters
- type (Type) - reads it.
Returns
Type: DmMigrator
This migrator.
AddTable
Registers a table model.
DmMigrator AddTable(DmTable table)Parameters
- table (DmTable) - The model.
Returns
Type: DmMigrator
This migrator.
AddTablesFromAssembly
Registers every class in an assembly marked with DmTableAttribute.
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.
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.
Task<DmMigrationResult> 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.
Task<DmSchemaMigrationResult> 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
GetType()ToString
ToString()Equals
Equals()GetHashCode
GetHashCode()Properties
Options
Gets the options.
Type: DmMigrationOptions
Tables
Gets the registered table models, in the order registered.
Type: IReadOnlyList<DmTable>