public bool HasSameProperties(Constraint other, CompareConfig compareConfig) { return IsSimilar(other) && (Name == other.Name || compareConfig.IgnoreConstraintsNameMismatch) && Clustered == other.Clustered && Unique == other.Unique; }
public DatabaseDiff Compare(Database otherDb, CompareConfig compareConfig = null) { compareConfig = compareConfig ?? new CompareConfig(); var diff = new DatabaseDiff(); diff.Db = otherDb; if (!compareConfig.IgnoreProps) { //compare database properties foreach (DbProp p in Props) { DbProp p2 = otherDb.FindProp(p.Name); if (p.Script() != p2.Script()) { diff.PropsChanged.Add(p); } } } CompareTables(otherDb, compareConfig, diff); CompareRoutines(otherDb, compareConfig, diff); CompareForeignKeys(otherDb, compareConfig, diff); return diff; }
private void CompareTables(Database otherDb, CompareConfig compareConfig, DatabaseDiff diff) { Action<Table, Table> checkIfTableChanged = (t, t2) => { //compare mutual tables TableDiff tDiff = t.Compare(t2, compareConfig); if (tDiff.IsDiff) { diff.TablesDiff.Add(tDiff); } }; CheckSource(compareConfig.TablesCompareMethod, Tables, t => otherDb.FindTable(t.Name, t.Owner), t => diff.TablesAdded.Add(t), checkIfTableChanged); //get deleted tables CheckTarget(compareConfig.TablesCompareMethod, otherDb.Tables, t => FindTable(t.Name, t.Owner) == null, t => diff.TablesDeleted.Add(t)); }
private void CompareRoutines(Database otherDb, CompareConfig compareConfig, DatabaseDiff diff) { Action<Routine, Routine> checkIfRoutineChanged = (r, r2) => { if (compareConfig.IgnoreRoutinesTextMismatch) { return; } //compare mutual procs if (r.Text.Replace("\r\n", "\n") != r2.Text.Replace("\r\n", "\n")) { diff.RoutinesDiff.Add(r); } }; CheckSource(compareConfig.RoutinesCompareMethod, Routines, r => otherDb.FindRoutine(r.Name, r.Schema), r => diff.RoutinesAdded.Add(r), checkIfRoutineChanged); //get procs deleted in source db or added in target db CheckTarget(compareConfig.RoutinesCompareMethod, otherDb.Routines, r => FindRoutine(r.Name, r.Schema) == null, r => diff.RoutinesDeleted.Add(r)); }
private void CompareForeignKeys(Database otherDb, CompareConfig compareConfig, DatabaseDiff diff) { Action<ForeignKey, ForeignKey> checkIfFkChanged = (fk1, fk2) => { if (fk1.ScriptCreate() != fk2.ScriptCreate()) { diff.ForeignKeysDiff.Add(fk1); } }; CheckSource(compareConfig.ForeignKeysCompareMethod, ForeignKeys, fk => otherDb.FindForeignKey(fk.Name), fk => diff.ForeignKeysAdded.Add(fk), checkIfFkChanged); //get deleted foreign keys CheckTarget(compareConfig.ForeignKeysCompareMethod, otherDb.ForeignKeys, fk => FindForeignKey(fk.Name) == null, fk => diff.ForeignKeysDeleted.Add(fk)); }
public ColumnDiff Compare(Column c, CompareConfig compareConfig) { return new ColumnDiff(this, c, compareConfig); }
public ColumnDiff(Column target, Column source, CompareConfig compareConfig) { _compareConfig = compareConfig; Source = source; Target = target; }
public TableDiff Compare(Table otherTable, CompareConfig compareConfig) { var diff = new TableDiff(); diff.Owner = otherTable.Owner; diff.Name = otherTable.Name; CompareColumns(otherTable, compareConfig, diff); CompareConstraints(otherTable, compareConfig, diff); return diff; }
private void CompareConstraints(Table otherTable, CompareConfig compareConfig, TableDiff diff) { Action<Constraint, Constraint> checkIfConstraintChanged = (c, c2) => { if(!c.HasSameProperties(c2, compareConfig)) { diff.ConstraintsChanged.Add(c); }; }; Func<Constraint, Constraint> getOtherConstraint = (c) => { var c2 = otherTable.FindConstraint(c.Name); if(compareConfig.IgnoreConstraintsNameMismatch && c2 == null) return otherTable.FindSimilarConstraint(c); return c2; }; CheckSource(compareConfig.ConstraintsCompareMethod, Constraints, getOtherConstraint, c => diff.ConstraintsAdded.Add(c), checkIfConstraintChanged); Func<Constraint, bool> constraintExistsOnlyInTaget = (c) => { var c2 = FindConstraint(c.Name); if (compareConfig.IgnoreConstraintsNameMismatch && c2 == null) c2 = FindSimilarConstraint(c); return c2 == null; }; CheckTarget(compareConfig.ConstraintsCompareMethod, otherTable.Constraints, constraintExistsOnlyInTaget, c => diff.ConstraintsDeleted.Add(c)); }
private void CompareColumns(Table otherTable, CompareConfig compareConfig, TableDiff diff) { Action<Column, Column> checkIfColumnChanged = (c, c2) => { //compare mutual columns ColumnDiff cDiff = c.Compare(c2, compareConfig); if (cDiff.IsDiff) { diff.ColumnsDiff.Add(cDiff); } }; CheckSource(compareConfig.ColumnsCompareMethod, Columns, c => otherTable.Columns.Find(c.Name), c => diff.ColumnsAdded.Add(c), checkIfColumnChanged); CheckTarget(compareConfig.RoutinesCompareMethod, otherTable.Columns, c => Columns.Find(c.Name) == null, c => diff.ColumnsDroped.Add(c)); }