Exemple #1
0
        internal static bool IsMigrationContextChanged(this IMigrationModel migration, object objectHavingContext)
        {
            var context = objectHavingContext.GetMigrationContextFromObject();

            if (context != null && !Equals(context, migration?.GetMigrationContext()))
            {
                migration?.Reset(context);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Initialize MigrationCallingName and MigrationAssembly from <paramref name="model"/>
        /// </summary>
        /// <param name="model"></param>
        protected void InitMetadata(IMigrationModel model)
        {
            if (model == null)
            {
                return;
            }

            MigrationAssembly = model.GetType().Assembly;

            if (MigrationCallingNameConfigField.IsEmpty())
            {
                MigrationName = MigrationAssembly.GetName().Name;
            }
        }
 /// <summary>
 /// Constructor initializing from <paramref name="model"/>
 /// </summary>
 public MigrationMetadata(IMigrationModel model)
 {
     InitMetadata(model);
 }
Exemple #4
0
        /// <summary>
        /// Alter the table or its columns/options<br/>
        /// If <paramref name="migration"/>.SchemaPrefix have a value, the Syntax-OldName will be computed to {<paramref name="migration"/>.SchemaPrefix}{<paramref name="tableName"/>}<br/>
        /// If NOT, the Syntax-OldName will be the same as {<paramref name="tableName"/>}
        /// </summary>
        /// <param name="root">Expression root to extend</param>
        /// <param name="tableName">
        /// The table name to alter<br/>
        /// See summary-section how this parameter is used
        /// </param>
        /// <param name="migration"><see cref="IMigrationModel"/></param>
        /// <returns>The interface for the modifications - <see cref="IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax"/></returns>
        public static IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax Table(this IAlterExpressionRoot root, string tableName, IMigrationModel migration)
        {
            var syntax = root.Table(migration.GetPrefixedName(tableName));

            syntax.InSchema(migration.SchemaName);
            return(syntax);
        }
Exemple #5
0
        /// <summary>
        /// Renames a table in Schema {<paramref name="migration"/>.SchemaName}<br/>
        /// If <paramref name="migration"/>.SchemaPrefix have a value, the Syntax-OldName will be computed to {<paramref name="migration"/>.SchemaPrefix}{<paramref name="oldName"/>}<br/>
        /// If NOT, the Syntax-OldName will be the same as {<paramref name="oldName"/>}
        /// </summary>
        /// <param name="root">Expression root to extend</param>
        /// <param name="oldName">
        /// The current table name<br/>
        /// See summary-section how this parameter is used
        /// </param>
        /// <param name="migration">FluentDbTools <see cref="IMigrationModel"/></param>
        /// <returns>The next step</returns>
        public static IRenameTableToOrInSchemaSyntax Table(this IRenameExpressionRoot root, string oldName, IMigrationModel migration)
        {
            var syntax = root.Table(migration.GetPrefixedName(oldName));

            syntax.InSchema(migration.SchemaName);
            return(syntax);
        }
Exemple #6
0
 /// <summary>
 /// ChangeLog activation for Delete.Table(..) syntax <br/>
 /// ----------------------------------------------------<br/>
 /// It will be possible to add custom logging on all table operations.<br/>
 /// The interface <see cref="ICustomMigrationProcessor{T}"/> must be implemented and registered in the IoC container (<see cref="IServiceCollection"/> )<br/>
 /// Method <see cref="ICustomMigrationProcessor.Process(IChangeLogTabledExpression)"/><br/>
 /// can be used to implementing your preferred custom logging <br/>
 /// <br/>
 /// See the example of a implementation of <see cref="ICustomMigrationProcessor{T}"/>:<br/>
 /// <a href="https://github.com/DIPSAS/FluentDbTools/blob/master/src/FluentDbTools/Tests/Test.FluentDbTools.Migration/TestOracleCustomMigrationProcessor.cs">https://github.com/DIPSAS/FluentDbTools/blob/master/src/FluentDbTools/Tests/Test.FluentDbTools.Migration/TestOracleCustomMigrationProcessor.cs</a><br/>
 /// <br/>
 /// Can be registered like this:<br/>
 /// <code type="csharp">
 ///     <see cref="IServiceCollection">serviceCollection</see>.AddSingleton&lt;ICustomMigrationProcessor&lt;OracleProcessor&gt;,TestOracleCustomMigrationProcessor&gt;();
 /// </code>
 /// </summary>
 /// <param name="syntax"></param>
 /// <param name="changeLog"></param>
 /// <param name="migration"></param>
 /// <returns><see cref="IInSchemaSyntax"/></returns>
 public static IInSchemaSyntax WithChangeLog(this IInSchemaSyntax syntax, ChangeLogContext changeLog, IMigrationModel migration)
 {
     return(AddChangeLogDynamicSyntax(syntax, changeLog, migration));
 }
Exemple #7
0
 /// <summary>
 /// ChangeLog activation for Rename.Table(..) syntax <br/>
 /// ----------------------------------------------------<br/>
 /// It will be possible to add custom logging on all table operations.<br/>
 /// The interface <see cref="ICustomMigrationProcessor{T}"/> must be implemented and registered in the IoC container (<see cref="IServiceCollection"/> )<br/>
 /// Method <see cref="ICustomMigrationProcessor.Process(IChangeLogTabledExpression)"/><br/>
 /// can be used to implementing your preferred custom logging <br/>
 /// <br/>
 /// See the example of a implementation of <see cref="ICustomMigrationProcessor{T}"/>:<br/>
 /// <a href="https://github.com/DIPSAS/FluentDbTools/blob/master/src/FluentDbTools/Tests/Test.FluentDbTools.Migration/TestOracleCustomMigrationProcessor.cs">https://github.com/DIPSAS/FluentDbTools/blob/master/src/FluentDbTools/Tests/Test.FluentDbTools.Migration/TestOracleCustomMigrationProcessor.cs</a><br/>
 /// <br/>
 /// Can be registered like this:<br/>
 /// <code type="csharp">
 ///     <see cref="IServiceCollection">serviceCollection</see>.AddSingleton&lt;ICustomMigrationProcessor&lt;OracleProcessor&gt;,TestOracleCustomMigrationProcessor&gt;();
 /// </code>
 /// </summary>
 /// <param name="syntax"></param>
 /// <param name="changeLog"></param>
 /// <param name="migration"></param>
 /// <returns><see cref="IRenameTableToSyntax"/></returns>
 public static T WithChangeLog <T>(this T syntax, ChangeLogContext changeLog, IMigrationModel migration) where T : IRenameTableToSyntax
 {
     return(AddChangeLogDynamicSyntax(syntax, changeLog, migration));
 }
Exemple #8
0
 /// <summary>
 /// ChangeLog activation for Rename.Column(..) syntax <br/>
 /// ----------------------------------------------------<br/>
 /// It will be possible to add custom logging on all table operations.<br/>
 /// The interface <see cref="ICustomMigrationProcessor{T}"/> must be implemented and registered in the IoC container (<see cref="IServiceCollection"/> )<br/>
 /// Method <see cref="ICustomMigrationProcessor.Process(IChangeLogTabledExpression)"/><br/>
 /// can be used to implementing your preferred custom logging <br/>
 /// <br/>
 /// See the example of a implementation of <see cref="ICustomMigrationProcessor{T}"/>:<br/>
 /// <a href="https://github.com/DIPSAS/FluentDbTools/blob/master/src/FluentDbTools/Tests/Test.FluentDbTools.Migration/TestOracleCustomMigrationProcessor.cs">https://github.com/DIPSAS/FluentDbTools/blob/master/src/FluentDbTools/Tests/Test.FluentDbTools.Migration/TestOracleCustomMigrationProcessor.cs</a><br/>
 /// <br/>
 /// Can be registered like this:<br/>
 /// <code type="csharp">
 ///     <see cref="IServiceCollection">serviceCollection</see>.AddSingleton&lt;ICustomMigrationProcessor&lt;OracleProcessor&gt;,TestOracleCustomMigrationProcessor&gt;();
 /// </code>
 /// </summary>
 /// <param name="syntax"></param>
 /// <param name="changeLog"></param>
 /// <param name="migration"></param>
 /// <returns><see cref="IRenameColumnToSyntax"/></returns>
 public static IRenameColumnToSyntax WithChangeLog(this IRenameColumnToSyntax syntax, ChangeLogContext changeLog, IMigrationModel migration)
 {
     return(AddChangeLogDynamicSyntax(syntax, changeLog, migration));
 }
Exemple #9
0
 /// <summary>
 /// Specify the new column name.
 /// </summary>
 /// <param name="syntax">Rename Column Syntax to extend</param>
 /// <param name="newColumnName">The new column name</param>
 /// <param name="migration">null can be used</param>
 /// <returns>Return the <paramref name="syntax"/></returns>
 public static IRenameColumnToSyntax To(this IRenameColumnToSyntax syntax, string newColumnName, IMigrationModel migration)
 {
     syntax.To(newColumnName);
     return(syntax);
 }
Exemple #10
0
        /// <summary>
        /// Specify the new name of the table<br/>
        /// If <paramref name="migration"/>.SchemaPrefix have a value, the Syntax-TableName will be computed to {<paramref name="migration"/>.SchemaPrefix}{<paramref name="tableName"/>}<br/>
        /// If NOT, the Syntax-TableName will be the same as {<paramref name="tableName"/>}
        /// </summary>
        /// <param name="syntax">Syntax to extend</param>
        /// <param name="tableName">
        /// The new table name<br/>
        /// See summary-section how this parameter is used
        /// </param>
        /// <param name="migration"></param>
        /// <returns>return <see cref="IInSchemaSyntax"/></returns>
        public static IInSchemaSyntax ToTable(this IRenameTableToOrInSchemaSyntax syntax, string tableName, IMigrationModel migration)
        {
            var tableSyntax = syntax.To(migration.GetPrefixedName(tableName));

            tableSyntax.InSchema(migration.SchemaName);
            return(tableSyntax);
        }
Exemple #11
0
        /// <summary>
        /// Specify the table for the new column<br/>
        /// If <paramref name="migration"/>.SchemaPrefix have a value, the Syntax-TableName will be computed to {<paramref name="migration"/>.SchemaPrefix}{<paramref name="tableName"/>}<br/>
        /// If NOT, the Syntax-TableName will be the same as {<paramref name="tableName"/>}
        /// </summary>
        /// <param name="syntax">Syntax to extend</param>
        /// <param name="tableName">
        /// The table name for the new column <br/>
        /// See summary-section how this parameter is used
        /// </param>
        /// <param name="migration"></param>
        /// <returns>The interface to specify the table schema or column information</returns>
        public static ICreateColumnAsTypeOrInSchemaSyntax OnTable(this ICreateColumnOnTableSyntax syntax, string tableName, IMigrationModel migration)
        {
            var tableSyntax = syntax.OnTable(migration.GetPrefixedName(tableName));

            tableSyntax.InSchema(migration.SchemaName);
            return(tableSyntax);
        }
Exemple #12
0
        /// <summary>
        /// Specify the table to delete<br/>
        /// If <paramref name="migration"/>.SchemaPrefix have a value, the Syntax-OldName will be computed to {<paramref name="migration"/>.SchemaPrefix}{<paramref name="tableName"/>}<br/>
        /// If NOT, the Syntax-OldName will be the same as {<paramref name="tableName"/>}
        /// </summary>
        /// <param name="root">Expression root to extend</param>
        /// <param name="tableName">
        /// The table name to delete<br/>
        /// See summary-section how this parameter is used
        /// </param>
        /// <param name="migration"></param>
        /// <returns>The next step - <see cref="IInSchemaSyntax"/></returns>
        public static IInSchemaSyntax Table(this IDeleteExpressionRoot root, string tableName, IMigrationModel migration)
        {
            var syntax = root.Table(tableName.GetPrefixedName(migration?.SchemaPrefixId));

            syntax.InSchema(migration?.SchemaName);
            return(syntax);
        }
Exemple #13
0
        private static T AddChangeLogDynamicSyntax <T>(T syntax, ChangeLogContext changeLog, IMigrationModel migration)
        {
            var expressions = migration?.GetExpressions();

            if (syntax is RenameTableExpressionBuilder renameTableBuilder)
            {
                expressions?.Insert(renameTableBuilder.Expression, new ChangeLogLinkedExpression(renameTableBuilder, changeLog), true);
                return(syntax);
            }
            if (syntax is RenameColumnExpressionBuilder renameColumnBuilder)
            {
                expressions?.Insert(renameColumnBuilder.Expression, new ChangeLogLinkedExpression(renameColumnBuilder, changeLog), true);
                return(syntax);
            }

            if (syntax is DeleteTableExpressionBuilder deleteTableBuilder)
            {
                expressions.Insert(deleteTableBuilder.Expression, new ChangeLogLinkedExpression(deleteTableBuilder, changeLog), true);
                return(syntax);
            }

            if (syntax is DeleteColumnExpressionBuilder deleteColumnBuilder)
            {
                expressions?.Insert(deleteColumnBuilder.Expression, new ChangeLogLinkedExpression(deleteColumnBuilder, changeLog), true);
                return(syntax);
            }

            return(syntax);
        }
Exemple #14
0
 /// <summary>
 /// Constructor<br/>
 /// -------------<br/>
 /// Inherited from constructor <see cref="ChangeLogContext(IDbMigrationConfig,string)"/><br/>
 /// SchemaPrefixId is assigned with value from <paramref name="model"/>(<see cref="IMigrationModel.GetMigrationConfig()"/>)  - method <see cref="IDbConfigSchemaTargets.GetSchemaPrefixId()"/><br/>
 /// SchemaPrefixUniqueId is assigned with value from <paramref name="model"/>(<see cref="IMigrationModel.GetMigrationConfig()"/>)  - method <see cref="IDbMigrationConfig.GetSchemaPrefixUniqueId()"/><br/>
 /// ShortName is assigned value from configuration database:migration:schemaPrefix:tables:{tableName}:ShortName or database:schemaPrefix:tables:{tableName}:ShortName<br/>
 /// GlobalId is assigned value from configuration database:migration:schemaPrefix:tables:{tableName}:GlobalId or database:schemaPrefix:tables:{tableName}:GlobalId<br/>
 /// <br/>
 /// i.e:<br/>
 /// When configuration have database:migration:schemaPrefix:Id = "PR" and database:migration:schemaPrefix:UniqueId = "abode" <br/>
 /// SchemaPrefixId will be resolved to "PR"<br/>
 /// SchemaPrefixUniqueId will be resolved to "abode"<br/>
 /// <br/>
 /// When <paramref name="tableName"/> is "testing", <br/>
 /// ShortName is fetched from database:migration:schemaPrefix:tables:testing:ShortName or database:schemaPrefix:tables:testing:ShortName<br/>
 /// GlobalId is fetched from database:migration:schemaPrefix:tables:testing:GlobalId or database:schemaPrefix:tables:testing:GlobalId<br/>
 /// </summary>
 /// <param name="model"></param>
 /// <param name="tableName"></param>
 public ChangeLogContext(IMigrationModel model, string tableName)
     : this(model?.GetMigrationConfig(), tableName)
 {
 }
Exemple #15
0
 public ChangeLogContext(IMigrationModel model)
     : this(model.GetMigrationConfig())
 {
     InitMetadata(model);
 }