コード例 #1
0
ファイル: Database.cs プロジェクト: nbidwell/SQLUpdater
 /// <summary>
 /// Copies the contents of this database to another.
 /// </summary>
 /// <param name="sink">The database to copy to.</param>
 public void CopyTo(Database sink)
 {
     Constraints.CopyTo(sink.Constraints);
     FulltextCatalogs.CopyTo(sink.FulltextCatalogs);
     FulltextIndexes.CopyTo(sink.FulltextIndexes);
     Functions.CopyTo(sink.Functions);
     Permissions.CopyTo(sink.Permissions);
     Procedures.CopyTo(sink.Procedures);
     Tables.CopyTo(sink.Tables);
     Triggers.CopyTo(sink.Triggers);
     TriggerOrder.CopyTo(sink.TriggerOrder);
     Views.CopyTo(sink.Views);
 }
コード例 #2
0
ファイル: TriggerOrder.cs プロジェクト: nbidwell/SQLUpdater
        /// <summary>
        /// Gets the differences between this item and another of the same type
        /// </summary>
        /// <param name="other">Another item of the same type</param>
        /// <param name="allDifferences">if set to <c>true</c> collects all differences,
        /// otherwise only the first difference is collected.</param>
        /// <returns>
        /// A Difference if there are differences between the items, otherwise null
        /// </returns>
        public override Difference GetDifferences(Item other, bool allDifferences)
        {
            TriggerOrder otherOrder = other as TriggerOrder;

            if (otherOrder == null)
            {
                return(new Difference(DifferenceType.Created, Name));
            }

            Difference difference = new Difference(DifferenceType.Modified, Name);

            if (Order != otherOrder.Order)
            {
                difference.AddMessage("Order", otherOrder.Order, Order);
                if (!allDifferences)
                {
                    return(difference);
                }
            }
            if (StatementType != otherOrder.StatementType)
            {
                difference.AddMessage("Statement Type", otherOrder.StatementType, StatementType);
                if (!allDifferences)
                {
                    return(difference);
                }
            }
            if (Trigger != otherOrder.Trigger)
            {
                difference.AddMessage("Trigger", otherOrder.Trigger, Trigger);
                if (!allDifferences)
                {
                    return(difference);
                }
            }

            return(difference.Messages.Count > 0 ? difference : null);
        }
コード例 #3
0
ファイル: Database.cs プロジェクト: nbidwell/SQLUpdater
        /// <summary>
        /// Gets the differences between this database and another.
        /// </summary>
        /// <param name="other">The other database.</param>
        /// <returns></returns>
        public DifferenceSet GetDifferences(Database other)
        {
            CalculateDependencies();
            other.CalculateDependencies();

            DifferenceSet differences = new DifferenceSet();

            //check table differences
            Tables.GetDifferences(other.Tables, dependencies, other.dependencies, differences);

            foreach (Table table in Tables)
            {
                Table otherTable = (Table)other.Tables[table.Name];
                table.Indexes.GetDifferences(otherTable == null ? null : otherTable.Indexes, dependencies, other.dependencies,
                                             differences);
                if (!table.Data.AreEqual(otherTable == null ? null : otherTable.Data))
                {
                    differences.Add(new Difference(DifferenceType.TableData, table.Data.Name, table.Name),
                                    otherTable == null ? null : dependencies);
                }
            }
            foreach (Table otherTable in other.Tables)
            {
                Table table = (Table)Tables[otherTable.Name];
                if (table == null)
                {
                    foreach (Index index in otherTable.Indexes)
                    {
                        differences.Add(new Difference(DifferenceType.Removed, index.Name, otherTable.Name), other.dependencies);
                    }
                }
            }

            //check constraint differences
            Constraints.GetDifferences(other.Constraints, dependencies, other.dependencies, differences);

            //deal with changing names...
            foreach (Constraint constraint in Constraints)
            {
                Table constrainedTable = other.Tables[constraint.ConstrainedTable];
                if (constrainedTable == null)
                {
                    continue;
                }

                if (constraint.Type == ConstraintType.Default)
                {
                    foreach (Name dependency in other.dependencies[constrainedTable.Name])
                    {
                        Constraint otherConstraint = other[dependency] as Constraint;
                        if (otherConstraint != null &&
                            otherConstraint.Type == ConstraintType.Default &&
                            constraint.ConstrainedTable == otherConstraint.ConstrainedTable &&
                            constraint.ColumnsEqual(otherConstraint) &&
                            constraint != otherConstraint
                            )
                        {
                            differences.Add(new Difference(DifferenceType.Removed, otherConstraint.Name), other.dependencies);
                            break;
                        }
                    }
                }
                else if (constraint.Type == ConstraintType.ForeignKey && other.Tables[constraint.ConstrainedTable] != null)
                {
                    foreach (Name dependency in other.dependencies[constrainedTable.Name])
                    {
                        Constraint otherConstraint = other[dependency] as Constraint;
                        if (otherConstraint != null &&
                            otherConstraint.Type == ConstraintType.ForeignKey &&
                            constraint.ConstrainedTable == otherConstraint.ConstrainedTable &&
                            constraint.ReferencedTable == otherConstraint.ReferencedTable &&
                            constraint.ColumnsEqual(otherConstraint) &&
                            constraint != otherConstraint
                            )
                        {
                            differences.Add(new Difference(DifferenceType.Removed, otherConstraint.Name), other.dependencies);
                            break;
                        }
                    }
                }
                else if (constraint.Type == ConstraintType.PrimaryKey && other.Tables[constraint.ConstrainedTable] != null)
                {
                    foreach (Name dependency in other.dependencies[constrainedTable.Name])
                    {
                        Constraint otherConstraint = other[dependency] as Constraint;
                        if (otherConstraint != null &&
                            otherConstraint.Type == ConstraintType.PrimaryKey &&
                            constraint.ConstrainedTable == otherConstraint.ConstrainedTable &&
                            constraint != otherConstraint
                            )
                        {
                            differences.Add(new Difference(DifferenceType.Removed, otherConstraint.Name), other.dependencies);
                            break;
                        }
                    }
                }
            }

            //check function differences
            Functions.GetDifferences(other.Functions, dependencies, other.dependencies, differences);

            //check fulltext catalog differences
            FulltextCatalogs.GetDifferences(other.FulltextCatalogs, dependencies, other.dependencies, differences);

            //check fulltext index differences
            FulltextIndexes.GetDifferences(other.FulltextIndexes, dependencies, other.dependencies, differences);

            //check procedure differences
            Procedures.GetDifferences(other.Procedures, dependencies, other.dependencies, differences);

            //check trigger differences
            Triggers.GetDifferences(other.Triggers, dependencies, other.dependencies, differences);

            //check trigger order differences
            TriggerOrder.GetDifferences(other.TriggerOrder, dependencies, other.dependencies, differences);

            //check view differences
            Views.GetDifferences(other.Views, dependencies, other.dependencies, differences);

            foreach (View view in Views)
            {
                View otherView = (View)other.Views[view.Name];
                view.Indexes.GetDifferences(otherView == null ? null : otherView.Indexes, dependencies, other.dependencies,
                                            differences);
            }

            foreach (View view in Views)
            {
                View otherView = (View)other.Views[view.Name];
                if (otherView != null)
                {
                    view.Indexes.GetDifferences(otherView.Indexes, dependencies, other.dependencies, differences);
                }
            }

            //check for new permissions
            Permissions.GetDifferences(other.Permissions, differences);

            return(differences);
        }