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.
DataProviderMigration<TDataProvider> (DbContext context, String[] scriptFolderNames, IEventDispatcher eventDispatcher, ILogger<TDataProvider> logger)
Constructor.
Parameters
Name Type
context Nucleus.Data.EntityFramework.DbContext
scriptFolderNames String[]
eventDispatcher Nucleus.Abstractions.EventHandlers.IEventDispatcher
logger Microsoft.Extensions.Logging.ILogger<TDataProvider>
Entity framework dbcontext for this instance.
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 operation)
Apply corrections for an AddColumnOperation, which could be standalone, or part of a create table operation.
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.
Remarks
The default schema name is the base namespace for the data provider class specified in the constructor.
ExecuteCommand (DatabaseSchemaScript script, String command)
Execute the command specified as string in command.
Parameters
Name Type
script Nucleus.Data.Common.DatabaseSchemaScript
command String
ExecuteCommand (DatabaseSchemaScript script, MigrationOperation operation)
Execute the command represented as a MigrationOperation object in operation.
GetSchemaVersion (String schemaName)
Retrieve the version number of the latest schema update that has been applied for the specified schema name.
Parameters
Name Type
schemaName String
Remarks
If no schema entry exists for the specified schema name, this function returns null.
RunDatabaseScripts (String schemaName, Version currentSchemaVersion, IList<DatabaseSchemaScript> scripts)
Execute all scripts which have a version greater than the current schema version.
Parameters
Name Type
schemaName String
currentSchemaVersion Version
scripts System.Collections.Generic.IList<Nucleus.Data.Common.DatabaseSchemaScript>
RunScript (String schemaName, DatabaseSchemaScript script)
Execute the commands in the script file. Commands are separated by "GO", followed by CRLF, LR or CR.
Parameters
Name Type
schemaName String
script Nucleus.Data.Common.DatabaseSchemaScript
Remarks
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.
SchemaTableExists ()
Check whether the Schema table exists in a database-agnostic way by quering it.
Remarks
Data provider implementations can override this method to check whether the table exists using a database-specific method (without relying on exceptions).
UpdateSchemaVersion (String schemaName, Version version)
Add or update a record in the schema table with the specified schema name and version.
Parameters
Name Type
schemaName String
version Version
Remarks
This function is called after a schema update has been applied.