/// <summary>
        /// Compares database data-types if schematicly match each other
        /// </summary>
        /// <param name="masterObjectType">Master database data type (or left)</param>
        /// <param name="checkedObjectType">Checked database data type (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectTypeSchema masterObjectType, DbObjectTypeSchema checkedObjectType)
        {
            if (masterObjectType == null)
            {
                throw new ArgumentNullException(nameof(masterObjectType));
            }

            if (checkedObjectType == null)
            {
                throw new ArgumentNullException(nameof(checkedObjectType));
            }

            bool equal = masterObjectType.SqlType == checkedObjectType.SqlType && masterObjectType.Lenght == checkedObjectType.Lenght &&
                         masterObjectType.Precision == checkedObjectType.Precision && masterObjectType.Scale == checkedObjectType.Scale && masterObjectType.AllowNull == checkedObjectType.AllowNull;

            DbSchemaCompareResult result = new DbSchemaCompareResult(masterObjectType, checkedObjectType);

            if (equal)
            {
                result.CompareResultType = DbSchemaCompareResultType.Equals;
            }
            else
            {
                result.CompareResultType = DbSchemaCompareResultType.Different;
            }

            return(result);
        }
        /// <summary>
        /// Compares databas functions if schematicly match each other
        /// </summary>
        /// <param name="masterObjectFunction">Master database function (or left)</param>
        /// <param name="checkedObjectFunction">Checked database function (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectFunctionSchema masterObjectFunction, DbObjectFunctionSchema checkedObjectFunction)
        {
            if (masterObjectFunction == null)
            {
                throw new ArgumentNullException(nameof(masterObjectFunction));
            }

            if (checkedObjectFunction == null)
            {
                throw new ArgumentNullException(nameof(checkedObjectFunction));
            }

            //masterObjectFunction.ReturnValues.Sort((l, r) => l.FakeOrderId.CompareTo(r.FakeOrderId));
            //checkedObjectFunction.ReturnValues.Sort((l, r) => l.FakeOrderId.CompareTo(r.FakeOrderId));

            DbSchemaCompareResult result = DbObjectStoredProcedureSchema.DbCompare(masterObjectFunction, checkedObjectFunction);

            foreach (DbObjectParameterSchema fMasterParam in masterObjectFunction.ReturnValues)
            {
                DbObjectParameterSchema fCheckParam = checkedObjectFunction.ReturnValues.FirstOrDefault(p => p.Name == fMasterParam.Name);
                result.InnerResults.Add(DbObjectParameterSchema.DbCompare(fMasterParam, fCheckParam));
            }

            foreach (DbObjectParameterSchema fCheckParam in checkedObjectFunction.ReturnValues)
            {
                DbObjectParameterSchema?fMasterParam = masterObjectFunction.ReturnValues.FirstOrDefault(p => p.Name == fCheckParam.Name);
                if (fMasterParam == null)
                {
                    result.InnerResults.Add(DbObjectParameterSchema.DbCompare(null, fCheckParam));
                }
            }

            return(result);
        }
        /// <summary>
        /// Compares database table columns if schematicly match each other
        /// </summary>
        /// <param name="masterColumn">Master database table column (or left)</param>
        /// <param name="checkedColumn">Checked database table column (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectTableColumnSchema masterColumn, DbObjectTableColumnSchema checkedColumn)
        {
            if (masterColumn == null)
            {
                throw new ArgumentNullException(nameof(masterColumn));
            }

            if (checkedColumn == null)
            {
                throw new ArgumentNullException(nameof(checkedColumn));
            }

            DbSchemaCompareResult result = DbObjectParameterSchema.DbCompare(masterColumn, checkedColumn);

            if (masterColumn.DefaultValue != checkedColumn.DefaultValue)
            {
                result.CompareResultType = DbSchemaCompareResultType.Different;
            }

            if (masterColumn.Collation != checkedColumn.Collation)
            {
                result.CompareResultType = DbSchemaCompareResultType.Different;
            }

            return(result);
        }
        /// <summary>
        /// Compares databases if schematicly match each other
        /// </summary>
        /// <param name="masterObjectCatalog">Master database catalog (or left)</param>
        /// <param name="checkedObjectCatalog">Checked database catalog (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectCatalogSchema masterObjectCatalog, DbObjectCatalogSchema checkedObjectCatalog)
        {
            if (checkedObjectCatalog == null)
            {
                throw new ArgumentNullException(nameof(checkedObjectCatalog));
            }

            DbSchemaCompareResult result = new DbSchemaCompareResult(masterObjectCatalog, checkedObjectCatalog);

            //SP
            CompareCollection(result, masterObjectCatalog.StoredProcedures, checkedObjectCatalog.StoredProcedures,
                              (left, right) => left.IsSameDbName(right), DbObjectStoredProcedureSchema.DbCompare);

            //FN
            CompareCollection(result, masterObjectCatalog.Functions, checkedObjectCatalog.Functions,
                              (left, right) => left.IsSameDbName(right), DbObjectFunctionSchema.DbCompare);

            //TFN
            CompareCollection(result, masterObjectCatalog.TableValuedFunctions, checkedObjectCatalog.TableValuedFunctions,
                              (left, right) => left.IsSameDbName(right), DbObjectFunctionSchema.DbCompare);

            //Tables
            CompareCollection(result, masterObjectCatalog.Tables, checkedObjectCatalog.Tables,
                              (left, right) => left.IsSameDbName(right), DbObjectTableSchema.DbCompare);

            //Views
            CompareCollection(result, masterObjectCatalog.Views, checkedObjectCatalog.Views,
                              (left, right) => left.IsSameDbName(right), DbObjectViewSchema.DbCompare);


            return(result);
        }
        /// <summary>
        /// Compares database stored procedures if schematicly match each other
        /// </summary>
        /// <param name="masterSp">Master database stored procedure (or left)</param>
        /// <param name="checkedSp">Checked database stored procedure (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectStoredProcedureSchema masterSp, DbObjectStoredProcedureSchema checkedSp)
        {
            if (masterSp == null)
            {
                throw new ArgumentNullException(nameof(masterSp));
            }

            if (checkedSp == null)
            {
                throw new ArgumentNullException(nameof(checkedSp));
            }

            DbSchemaCompareResult result = DbObjectTriggerSchema.DbCompare(masterSp, checkedSp);

            CompareCollection(result, masterSp.Parameters, checkedSp.Parameters, (left, right) => string.Equals(left.Name, right.Name, StringComparison.Ordinal),
                              DbObjectParameterSchema.DbCompare);

            return(result);
        }
        /// <summary>
        /// Compares database triggers if schematicly match each other
        /// </summary>
        /// <param name="masterObjectTrigger">Master database trigger (or left)</param>
        /// <param name="checkedObjectTrigger">Checked database trigger (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectTriggerSchema masterObjectTrigger, DbObjectTriggerSchema checkedObjectTrigger)
        {
            if (checkedObjectTrigger == null)
            {
                throw new ArgumentNullException(nameof(checkedObjectTrigger));
            }

            DbSchemaCompareResult result = new DbSchemaCompareResult(masterObjectTrigger, checkedObjectTrigger);

            if (string.Equals(masterObjectTrigger.ScriptText, checkedObjectTrigger.ScriptText, StringComparison.Ordinal))
            {
                result.CompareResultType = DbSchemaCompareResultType.Equals;
            }
            else
            {
                result.CompareResultType = DbSchemaCompareResultType.Different;
            }

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Compares database views if schematicly match each other
        /// </summary>
        /// <param name="masterObjectView">Master database objectView (or left)</param>
        /// <param name="checkedObjectView">Checked database objectView (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectViewSchema masterObjectView, DbObjectViewSchema checkedObjectView)
        {
            if (checkedObjectView == null)
            {
                throw new ArgumentNullException(nameof(checkedObjectView));
            }

            DbSchemaCompareResult result = new DbSchemaCompareResult(masterObjectView, checkedObjectView);

            result.CompareResultType = DbSchemaCompareResultType.Equals;

            foreach (DbSchemaCompareResult fColumnCompare in result.InnerResults)
            {
                if (fColumnCompare.CompareResultType != DbSchemaCompareResultType.Equals)
                {
                    fColumnCompare.CompareResultType = DbSchemaCompareResultType.Different;
                }
            }

            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// Compares database parameters if schematicly match each other
        /// </summary>
        /// <param name="masterParam">Master database catalog (or left)</param>
        /// <param name="checkedParam">Checked database catalog (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectParameterSchema?masterParam, DbObjectParameterSchema?checkedParam)
        {
            DbSchemaCompareResult result = new DbSchemaCompareResult(masterParam, checkedParam);

            if (checkedParam == null || masterParam == null)
            {
                result.CompareResultType = DbSchemaCompareResultType.Different;
            }
            else
            {
                result.InnerResults.Add(DbObjectTypeSchema.DbCompare(masterParam.DbObjectType, checkedParam.DbObjectType));
                if (masterParam.FakeOrderId == checkedParam.FakeOrderId)
                {
                    result.CompareResultType = DbSchemaCompareResultType.Equals;
                }
                else
                {
                    result.CompareResultType = DbSchemaCompareResultType.Different;
                }
            }

            return(result);
        }
 /// <summary>
 /// Compare collection of SbSchema objects to another collection of same type
 /// </summary>
 /// <typeparam name="T">Runtime type of SbSchema object</typeparam>
 /// <param name="result">Compare result object</param>
 /// <param name="leftList">Master collection</param>
 /// <param name="rightList">Check collection</param>
 /// <param name="equalityMethod">Method to identify "same" objects</param>
 /// <param name="compareMethod">Custom copmarison method</param>
 protected static void CompareCollection <T>(DbSchemaCompareResult result, IEnumerable <T> leftList, IEnumerable <T> rightList, Func <T, T, bool> equalityMethod,
                                             Func <T, T, DbSchemaCompareResult> compareMethod)
     where T : DbObjectSchemaBase
 {
     leftList.Indiferente(rightList, equalityMethod,
                          left =>
     {
         DbSchemaCompareResult leftResult = new DbSchemaCompareResult(left, null);
         leftResult.CompareResultType     = DbSchemaCompareResultType.Missing;
         result.InnerResults.Add(leftResult);
     },
                          right =>
     {
         DbSchemaCompareResult rightResult = new DbSchemaCompareResult(null, right);
         rightResult.CompareResultType     = DbSchemaCompareResultType.Redudant;
         result.InnerResults.Add(rightResult);
     },
                          (left, right) =>
     {
         DbSchemaCompareResult bothResult = compareMethod(left, right);
         result.InnerResults.Add(bothResult);
     });
 }
        /// <summary>
        /// Compares database tables if schematicly match each other
        /// </summary>
        /// <param name="masterObjectTable">Master database objectTable (or left)</param>
        /// <param name="checkedObjectTable">Checked database objectTable (or right)</param>
        /// <returns>Comparison result</returns>
        public static DbSchemaCompareResult DbCompare(DbObjectTableSchema masterObjectTable, DbObjectTableSchema checkedObjectTable)
        {
            if (checkedObjectTable == null)
            {
                throw new ArgumentNullException(nameof(checkedObjectTable));
            }

            DbSchemaCompareResult result = new DbSchemaCompareResult(masterObjectTable, checkedObjectTable);

            result.CompareResultType = DbSchemaCompareResultType.Equals;

            CompareCollection(result, masterObjectTable.Columns, checkedObjectTable.Columns, (left, right) => string.Equals(left.Name, right.Name, StringComparison.Ordinal),
                              DbObjectTableColumnSchema.DbCompare);

            foreach (DbSchemaCompareResult fColumnCompare in result.InnerResults)
            {
                if (fColumnCompare.CompareResultType != DbSchemaCompareResultType.Equals)
                {
                    fColumnCompare.CompareResultType = DbSchemaCompareResultType.Different;
                }
            }

            return(result);
        }