public void CanAddCategoryToCategoryForChangedColumn()
        {
            var diff = new DatabaseDiff();
            var tableDiff = new TableDiff();
            tableDiff.ColumnsDiff.Add(new ColumnDiff(new Column { Type = "text" }, new Column { Type = "text" }, new CompareConfig()));
            diff.TablesDiff.Add(tableDiff);

            var report = diff.GetDiffReport();

            report.Categories[0].Entries.Count.Should().Be(1);
            report.Categories[0].Entries[0].Categories.Count.Should().Be(1);
        }
        public void CanAddCategoryToCategoryForDeletedColumn()
        {
            var diff = new DatabaseDiff();
            var tableDiff = new TableDiff();
            tableDiff.ColumnsDroped.Add(new Column { Type = "text" });
            diff.TablesDiff.Add(tableDiff);

            var report = diff.GetDiffReport();

            report.Categories[0].Entries.Count.Should().Be(1);
            report.Categories[0].Entries[0].Categories.Count.Should().Be(1);
        }
        public void CanAddCategoryToCategoryForChangedConstraint()
        {
            var diff = new DatabaseDiff();
            var tableDiff = new TableDiff();
            tableDiff.ConstraintsChanged.Add(new Constraint("", "", "") { Table = new TableInfo("dbo", "myTable") });
            diff.TablesDiff.Add(tableDiff);

            var report = diff.GetDiffReport();

            report.Categories[0].Entries.Count.Should().Be(1);
            report.Categories[0].Entries[0].Categories.Count.Should().Be(1);
        }
        public void CanAddCorrectEntryForDeletedTable()
        {
            var diff = new DatabaseDiff();
            diff.TablesDeleted.Add(new Table("dbo", "MyTable"));

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("MyTable");
            entry.Type.Should().Be(DiffEntryType.Deleted);
        }
        public void CanAddCorrectEntryForDeletedForeignKey()
        {
            var diff = new DatabaseDiff();
            diff.ForeignKeysDeleted.Add(GetForeignKey());

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("My_FK");
            entry.Type.Should().Be(DiffEntryType.Deleted);
        }
        public void CanAddCorrectEntryForDeletedConstraint()
        {
            var diff = new DatabaseDiff();
            var tableDiff = new TableDiff();
            tableDiff.ConstraintsDeleted.Add(new Constraint("MyConstraint", "", "") { Table = new TableInfo("dbo", "myTable") });
            diff.TablesDiff.Add(tableDiff);

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries[0].Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("MyConstraint");
            entry.Type.Should().Be(DiffEntryType.Deleted);
        }
        public void CanAddCorrectEntryForDeletedColumn()
        {
            var diff = new DatabaseDiff();
            var tableDiff = new TableDiff();
            tableDiff.ColumnsDroped.Add(new Column { Name = "MyColumn", Type = "text" });
            diff.TablesDiff.Add(tableDiff);

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries[0].Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("MyColumn");
            entry.Type.Should().Be(DiffEntryType.Deleted);
        }
        public void CanAddCorrectEntryForChangedRoutine()
        {
            var diff = new DatabaseDiff();
            diff.RoutinesDiff.Add(new Routine("dbo","My_Routine"));

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("My_Routine");
            entry.Type.Should().Be(DiffEntryType.Changed);
        }
Exemple #9
0
        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;
        }
Exemple #10
0
        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));
        }
        public void CanAddCategoryWithChangedTable()
        {
            var diff = new DatabaseDiff();
            diff.TablesDiff.Add(new TableDiff());

            var report = diff.GetDiffReport();

            report.Categories.Count.Should().Be(1);
        }
        public void CanAddCategoryWithDeletedForeinKey()
        {
            var diff = new DatabaseDiff();
            diff.ForeignKeysDeleted.Add(GetForeignKey());

            var report = diff.GetDiffReport();

            report.Categories.Count.Should().Be(1);
        }
        public void CanAddCategoryWithChangedRoutine()
        {
            var diff = new DatabaseDiff();
            diff.RoutinesDiff.Add(new Routine("dbo", "MySP"));

            var report = diff.GetDiffReport();

            report.Categories.Count.Should().Be(1);
        }
        public void CanAddCategoryWithChangedProperty()
        {
            var diff = new DatabaseDiff();
            diff.PropsChanged.Add(new DbProp("prop", "value"));

            var report = diff.GetDiffReport();

            report.Categories.Count.Should().Be(1);
            report.Categories[0].Name.Should().Be("Properties");
        }
Exemple #15
0
        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));
        }
        public void CanCreateDiffReport()
        {
            var databaseDiff = new DatabaseDiff();

            var report = databaseDiff.GetDiffReport();

            report.Should().NotBeNull();
        }
Exemple #17
0
        public DatabaseDiff Compare(Database db)
        {
            var diff = new DatabaseDiff();
            diff.Db = db;

            //compare database properties
            foreach (DbProp p in Props)
            {
                DbProp p2 = db.FindProp(p.Name);
                if (p.Script() != p2.Script())
                {
                    diff.PropsChanged.Add(p);
                }
            }

            //get tables added and changed
            foreach (Table t in Tables)
            {
                Table t2 = db.FindTable(t.Name, t.Owner);
                if (t2 == null)
                {
                    diff.TablesAdded.Add(t);
                }
                else
                {
                    //compare mutual tables
                    TableDiff tDiff = t.Compare(t2);
                    if (tDiff.IsDiff)
                    {
                        diff.TablesDiff.Add(tDiff);
                    }
                }
            }
            //get deleted tables
            foreach (Table t in db.Tables)
            {
                if (FindTable(t.Name, t.Owner) == null)
                {
                    diff.TablesDeleted.Add(t);
                }
            }

            //get procs added and changed
            foreach (Routine r in Routines)
            {
                Routine r2 = db.FindRoutine(r.Name, r.Schema);
                if (r2 == null)
                {
                    diff.RoutinesAdded.Add(r);
                }
                else
                {
                    //compare mutual procs
                    if (r.Text != r2.Text)
                    {
                        diff.RoutinesDiff.Add(r);
                    }
                }
            }
            //get procs deleted
            foreach (Routine r in db.Routines)
            {
                if (FindRoutine(r.Name, r.Schema) == null)
                {
                    diff.RoutinesDeleted.Add(r);
                }
            }

            //get added and compare mutual foreign keys
            foreach (ForeignKey fk in ForeignKeys)
            {
                ForeignKey fk2 = db.FindForeignKey(fk.Name);
                if (fk2 == null)
                {
                    diff.ForeignKeysAdded.Add(fk);
                }
                else
                {
                    if (fk.ScriptCreate() != fk2.ScriptCreate())
                    {
                        diff.ForeignKeysDiff.Add(fk);
                    }
                }
            }
            //get deleted foreign keys
            foreach (ForeignKey fk in db.ForeignKeys)
            {
                if (FindForeignKey(fk.Name) == null)
                {
                    diff.ForeignKeysDeleted.Add(fk);
                }
            }

            return diff;
        }
        public void CanAddCategoryWithDeletedTable()
        {
            var diff = new DatabaseDiff();
            diff.TablesDeleted.Add(new Table("dbo", "MyTable"));

            var report = diff.GetDiffReport();

            report.Categories.Count.Should().Be(1);
        }
Exemple #19
0
        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 void CanAddCorrectEntryForChangedColumn()
        {
            var diff = new DatabaseDiff();
            var tableDiff = new TableDiff();
            tableDiff.ColumnsDiff.Add(new ColumnDiff(new Column { Name = "TargetColumn", Type = "text" }, new Column { Name = "SourceColumn", Type = "text" }, new CompareConfig()));
            diff.TablesDiff.Add(tableDiff);

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries[0].Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("SourceColumn");
            entry.Type.Should().Be(DiffEntryType.Changed);
        }
        public void CanAddCorrectEntryForChangedProperty()
        {
            var diff = new DatabaseDiff();
            diff.PropsChanged.Add(new DbProp("prop", "value"));

            var report = diff.GetDiffReport();

            DiffEntry entry;
            (entry = report.Categories[0].Entries.FirstOrDefault()).Should().NotBeNull();
            entry.Name.Should().Be("prop");
            entry.Type.Should().Be(DiffEntryType.Changed);
        }
Exemple #22
0
        public DatabaseDiff Compare(Database db)
        {
            var diff = new DatabaseDiff();

            diff.Db = db;

            //compare database properties
            foreach (DbProp p in Props)
            {
                DbProp p2 = db.FindProp(p.Name);
                if (p.Script() != p2.Script())
                {
                    diff.PropsChanged.Add(p);
                }
            }

            //get tables added and changed
            foreach (Table t in Tables)
            {
                Table t2 = db.FindTable(t.Name, t.Owner);
                if (t2 == null)
                {
                    diff.TablesAdded.Add(t);
                }
                else
                {
                    //compare mutual tables
                    TableDiff tDiff = t.Compare(t2);
                    if (tDiff.IsDiff)
                    {
                        diff.TablesDiff.Add(tDiff);
                    }
                }
            }
            //get deleted tables
            foreach (Table t in db.Tables)
            {
                if (FindTable(t.Name, t.Owner) == null)
                {
                    diff.TablesDeleted.Add(t);
                }
            }

            //get procs added and changed
            foreach (Routine r in Routines)
            {
                Routine r2 = db.FindRoutine(r.Name, r.Schema);
                if (r2 == null)
                {
                    diff.RoutinesAdded.Add(r);
                }
                else
                {
                    //compare mutual procs
                    if (r.Text != r2.Text)
                    {
                        diff.RoutinesDiff.Add(r);
                    }
                }
            }
            //get procs deleted
            foreach (Routine r in db.Routines)
            {
                if (FindRoutine(r.Name, r.Schema) == null)
                {
                    diff.RoutinesDeleted.Add(r);
                }
            }

            //get added and compare mutual foreign keys
            foreach (ForeignKey fk in ForeignKeys)
            {
                ForeignKey fk2 = db.FindForeignKey(fk.Name);
                if (fk2 == null)
                {
                    diff.ForeignKeysAdded.Add(fk);
                }
                else
                {
                    if (fk.ScriptCreate() != fk2.ScriptCreate())
                    {
                        diff.ForeignKeysDiff.Add(fk);
                    }
                }
            }
            //get deleted foreign keys
            foreach (ForeignKey fk in db.ForeignKeys)
            {
                if (FindForeignKey(fk.Name) == null)
                {
                    diff.ForeignKeysDeleted.Add(fk);
                }
            }

            return(diff);
        }
Exemple #23
0
        public DatabaseDiff Compare(Database db)
        {
            var diff = new DatabaseDiff();
            diff.Db = db;

            //compare database properties
            foreach (DbProp p in from p in Props
                let p2 = db.FindProp(p.Name)
                where p.Script() != p2.Script()
                select p) {
                diff.PropsChanged.Add(p);
            }

            //get tables added and changed
            foreach (Table t in Tables) {
                Table t2 = db.FindTable(t.Name, t.Owner);
                if (t2 == null) {
                    diff.TablesAdded.Add(t);
                } else {
                    //compare mutual tables
                    TableDiff tDiff = t.Compare(t2);
                    if (tDiff.IsDiff) {
                        diff.TablesDiff.Add(tDiff);
                    }
                }
            }
            //get deleted tables
            foreach (Table t in db.Tables.Where(t => FindTable(t.Name, t.Owner) == null)) {
                diff.TablesDeleted.Add(t);
            }

            //get procs added and changed
            foreach (Routine r in Routines) {
                Routine r2 = db.FindRoutine(r.Name, r.Schema);
                if (r2 == null) {
                    diff.RoutinesAdded.Add(r);
                } else {
                    //compare mutual procs
                    if (r.Text != r2.Text) {
                        diff.RoutinesDiff.Add(r);
                    }
                }
            }
            //get procs deleted
            foreach (Routine r in db.Routines.Where(r => FindRoutine(r.Name, r.Schema) == null)) {
                diff.RoutinesDeleted.Add(r);
            }

            //get added and compare mutual foreign keys
            foreach (ForeignKey fk in ForeignKeys) {
                ForeignKey fk2 = db.FindForeignKey(fk.Name);
                if (fk2 == null) {
                    diff.ForeignKeysAdded.Add(fk);
                } else {
                    if (fk.ScriptCreate() != fk2.ScriptCreate()) {
                        diff.ForeignKeysDiff.Add(fk);
                    }
                }
            }
            //get deleted foreign keys
            foreach (ForeignKey fk in db.ForeignKeys.Where(fk => FindForeignKey(fk.Name) == null)) {
                diff.ForeignKeysDeleted.Add(fk);
            }

            //get added and compare mutual assemblies
            foreach (SqlAssembly a in Assemblies) {
                SqlAssembly a2 = db.FindAssembly(a.Name);
                if (a2 == null) {
                    diff.AssembliesAdded.Add(a);
                } else {
                    if (a.ScriptCreate(this) != a2.ScriptCreate(db)) {
                        diff.AssembliesDiff.Add(a);
                    }
                }
            }
            //get deleted assemblies
            foreach (SqlAssembly a in db.Assemblies.Where(a => FindAssembly(a.Name) == null)) {
                diff.AssembliesDeleted.Add(a);
            }

            //get added and compare mutual users
            foreach (SqlUser u in Users) {
                SqlUser u2 = db.FindUser(u.Name);
                if (u2 == null) {
                    diff.UsersAdded.Add(u);
                } else {
                    if (u.ScriptCreate(this) != u2.ScriptCreate(db)) {
                        diff.UsersDiff.Add(u);
                    }
                }
            }
            //get deleted users
            foreach (SqlUser u in db.Users.Where(u => FindUser(u.Name) == null)) {
                diff.UsersDeleted.Add(u);
            }

            //get added and compare view indexes
            foreach (Constraint c in ViewIndexes) {
                Constraint c2 = db.FindViewIndex(c.Name);
                if (c2 == null) {
                    diff.ViewIndexesAdded.Add(c);
                } else {
                    if (c.Script() != c2.Script()) {
                        diff.ViewIndexesDiff.Add(c);
                    }
                }
            }
            //get deleted view indexes
            foreach (Constraint c in db.ViewIndexes.Where(c => FindViewIndex(c.Name) == null)) {
                diff.ViewIndexesDeleted.Add(c);
            }

            return diff;
        }