Nucleus .Net Core CMS

DataProviderMigration<TDataProvider> Class

Namespace: Nucleus.Data.EntityFramework
Assembly: Nucleus.Data.EntityFramework.dll
Methods to handle schema migration operations.
Type Parameters
TDataProvider Type of the data provider implementation that this class handles migration for.


Database-specific data migration implementations inherit this class in order to provide data migrations for their database schema.


Nucleus.Data.EntityFramework.DataProviderMigration<TDataProvider> Constructor

Nucleus.Data.EntityFramework.DataProviderMigration<TDataProvider> (DbContext context, String[] scriptFolderNames, IEventDispatcher eventDispatcher, ILogger<TDataProvider> logger)
Name Type
context Nucleus.Data.EntityFramework.DbContext
scriptFolderNames String[]
eventDispatcher Nucleus.Abstractions.EventHandlers.IEventDispatcher
logger Microsoft.Extensions.Logging.ILogger<TDataProvider>


DbContext Property

Entity framework dbcontext for this instance.



CheckDatabaseSchema ()
Compare the value matching the SchemaName property with the versions of available scripts, and apply any schema updates which have not already been applied.
The default schema name is the base namespace for the data provider class specified in the constructor.


SchemaTableExists ()
Check whether the Schema table exists in a database-agnostic way by quering it.
Data provider implementations can override this method to check whether the table exists using a database-specific method (without relying on exceptions).

GetSchemaVersion (String) Method

GetSchemaVersion (String schemaName)
Retrieve the version number of the latest schema update that has been applied for the specified schema name.
Name Type
schemaName String
If no schema entry exists for the specified schema name, this function returns null.

UpdateSchemaVersion (String,Version) Method

UpdateSchemaVersion (String schemaName, Version version)
Add or update a record in the schema table with the specified schema name and version.
Name Type
schemaName String
version Version
This function is called after a schema update has been applied.

RunDatabaseScripts (String,Version,IList<DatabaseSchemaScript>) Method

RunDatabaseScripts (String schemaName, Version currentSchemaVersion, IList<DatabaseSchemaScript> scripts)
Execute all scripts which have a version greater than the current schema version.
Name Type
schemaName String
currentSchemaVersion Version
scripts System.Collections.Generic.IList<Nucleus.Data.Common.DatabaseSchemaScript>

RunScript (String,DatabaseSchemaScript) Method

RunScript (String schemaName, DatabaseSchemaScript script)
Execute the commands in the script file. Commands are separated by "GO", followed by CRLF, LR or CR.
Name Type
schemaName String
script Nucleus.Data.Common.DatabaseSchemaScript
The use of either \r\n OR \n OR \r allows scripts created in various editors to be used successfully. Using Environment.Newline is not appropriate because the file format is specified by the developer's text editor, not the execution environment. Windows typically uses /r/n, Unix uses /n and Mac uses /r.

ApplyCorrections (MigrationOperation) Method

ApplyCorrections (MigrationOperation migrationOperation)
Set required properties on the migrationOperation to appropriate default values, based on other values set by the migration script and/or the database type.

ApplyCorrections (AddColumnOperation) Method

ApplyCorrections (AddColumnOperation operation)
Apply corrections for an AddColumnOperation, which could be standalone, or part of a create table operation.

ExecuteCommand (DatabaseSchemaScript,String) Method

ExecuteCommand (DatabaseSchemaScript script, String command)
Execute the command specified as string in command.
Name Type
script Nucleus.Data.Common.DatabaseSchemaScript
command String

ExecuteCommand (DatabaseSchemaScript,MigrationOperation) Method

ExecuteCommand (DatabaseSchemaScript script, MigrationOperation operation)
Execute the command represented as a MigrationOperation object in operation.