/// <summary> /// Gets the differences between two sets. /// </summary> /// <param name="other">The other set of permissions to compare against.</param> /// <param name="differences">The set of differences to fill.</param> public void GetDifferences(PermissionSet other, DifferenceSet differences) { foreach (Name name in permissions.Keys) { if (IsDifferent(other, differences, name)) { differences.Add(new Difference(DifferenceType.CreatedPermission, name), null); } } }
/// <summary> /// Gets the differences between this collection of items and another. /// </summary> /// <param name="other">The set of items to compare against.</param> /// <param name="dependencies">The dependencies for this collection.</param> /// <param name="otherDependencies">The dependencies for the other collection.</param> /// <param name="differences">The set of differences to fill.</param> public void GetDifferences(HashArray <T> other, DependencyCollection dependencies, DependencyCollection otherDependencies, DifferenceSet differences) { foreach (Item item in this) { Item otherItem = other == null ? null : other[item.Name]; Difference difference = item.GetDifferences(otherItem, true); if (difference != null) { differences.Add(difference, dependencies, otherDependencies); } } if (RunOptions.Current.FullyScripted && other != null) { foreach (Item otherItem in other) { if (this[otherItem.Name] == null) { differences.Add(new Difference(DifferenceType.Removed, otherItem.Name), otherDependencies); } } } }
/// <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); }