Esempio n. 1
0
        public void AddIndex()
        {
            var srcTable  = ModelBuilder.BuildTable("table1", "this", "that", "other", "Id");
            var destTable = ModelBuilder.BuildTable("table1", "this", "that", "other", "Id");

            var index = new ModelSync.Models.Index()
            {
                Parent  = destTable,
                Name    = "U_table1_this_that",
                Type    = IndexType.UniqueConstraint,
                Columns = new ModelSync.Models.Index.Column[]
                {
                    new ModelSync.Models.Index.Column()
                    {
                        Name = "this"
                    },
                    new ModelSync.Models.Index.Column()
                    {
                        Name = "that"
                    }
                }
            };

            srcTable.Indexes = new ModelSync.Models.Index[] { index };

            var srcModel = new DataModel()
            {
                Tables = new Table[] { srcTable }
            };
            var destModel = new DataModel()
            {
                Tables = new Table[] { destTable }
            };
            var diff = DataModel.Compare(srcModel, destModel);

            Assert.IsTrue(diff.Contains(new ScriptAction()
            {
                Type     = ActionType.Create,
                Object   = index,
                Commands = index.CreateStatements()
            }));
        }
Esempio n. 2
0
        public void DropTableWithoutRedundantIndexDrop()
        {
            var table1 = ModelBuilder.BuildTable("table1", "this", "that", "other", "Id");

            var index = new ModelSync.Models.Index()
            {
                Name    = "U_table1_this_that",
                Type    = IndexType.UniqueConstraint,
                Columns = new ModelSync.Models.Index.Column[]
                {
                    new ModelSync.Models.Index.Column()
                    {
                        Name = "this"
                    },
                    new ModelSync.Models.Index.Column()
                    {
                        Name = "that"
                    }
                }
            };

            table1.Indexes = new ModelSync.Models.Index[] { index };

            var srcModel  = new DataModel();
            var destModel = new DataModel()
            {
                Tables = new Table[] { table1 }
            };

            var diff = DataModel.Compare(srcModel, destModel);

            Assert.IsTrue(diff.Contains(new ScriptAction()
            {
                Type     = ActionType.Drop,
                Object   = table1,
                Commands = table1.DropStatements(destModel)
            }));
            Assert.IsTrue(diff.Count() == 1);
        }