コード例 #1
0
        /// <summary>
        /// Run the comparison and returns a <see cref="CompareResult"/>.
        /// </summary>
        /// <returns></returns>
        public IList<CompareResult> ExecuteResult()
        {
            var list = new List<CompareResult>();

            var compareTables = new CompareTables(list, _writer);
            //make sure they are in topological order- if 2 tables are added, the first must not have a foreign key to the second...
            var comparedTables = SchemaTablesSorter.TopologicalSort(_compareSchema);
            compareTables.Execute(_baseSchema.Tables, comparedTables);

            //compare sequences
            var compareSequences = new CompareSequences(list, _writer);
            compareSequences.Execute(_baseSchema.Sequences, _compareSchema.Sequences);

            //compare views
            var compareViews = new CompareViews(list, _writer);
            compareViews.Execute(_baseSchema.Views, _compareSchema.Views);

            //compare stored procedures and functions
            var compareProcedures = new CompareProcedures(list, _writer);
            compareProcedures.Execute(_baseSchema.StoredProcedures, _compareSchema.StoredProcedures);
            var compareFunctions = new CompareFunctions(list, _writer);
            compareFunctions.Execute(_baseSchema.Functions, _compareSchema.Functions);

            //compare packages
            var comparePackages = new ComparePackages(list, _writer);
            comparePackages.Execute(_baseSchema.Packages, _compareSchema.Packages);

            return list;
        }
コード例 #2
0
        /// <summary>
        /// Run the comparison.
        /// </summary>
        /// <returns></returns>
        public string Execute()
        {
            var sb = new StringBuilder();

            var compareTables = new CompareTables(sb, _writer);
            //make sure they are in topological order- if 2 tables are added, the first must not have a foreign key to the second...
            var comparedTables = SchemaTablesSorter.TopologicalSort(_compareSchema);

            compareTables.Execute(_baseSchema.Tables, comparedTables);

            //compare sequences
            var compareSequences = new CompareSequences(sb, _writer);

            compareSequences.Execute(_baseSchema.Sequences, _compareSchema.Sequences);

            //compare views
            var compareViews = new CompareViews(sb, _writer);

            compareViews.Execute(_baseSchema.Views, _compareSchema.Views);

            //compare stored procedures and functions
            var compareProcedures = new CompareProcedures(sb, _writer);

            compareProcedures.Execute(_baseSchema.StoredProcedures, _compareSchema.StoredProcedures);
            var compareFunctions = new CompareFunctions(sb, _writer);

            compareFunctions.Execute(_baseSchema.Functions, _compareSchema.Functions);

            //compare packages
            var comparePackages = new ComparePackages(sb, _writer);

            comparePackages.Execute(_baseSchema.Packages, _compareSchema.Packages);

            return(sb.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Run the comparison and returns a <see cref="CompareResult"/>.
        /// </summary>
        /// <returns></returns>
        public IList <CompareResult> ExecuteResult()
        {
            var list = new List <CompareResult>();

            var compareTables = new CompareTables(list, _writer);
            //make sure they are in topological order- if 2 tables are added, the first must not have a foreign key to the second...
            var comparedTables = SchemaTablesSorter.TopologicalSort(_compareSchema);

            compareTables.Execute(_baseSchema.Tables, comparedTables);

            //compare sequences
            var compareSequences = new CompareSequences(list, _writer);

            compareSequences.Execute(_baseSchema.Sequences, _compareSchema.Sequences);

            //compare views
            var compareViews = new CompareViews(list, _writer);

            compareViews.Execute(_baseSchema.Views, _compareSchema.Views);

            //compare stored procedures and functions
            var compareProcedures = new CompareProcedures(list, _writer);

            compareProcedures.Execute(_baseSchema.StoredProcedures, _compareSchema.StoredProcedures);
            var compareFunctions = new CompareFunctions(list, _writer);

            compareFunctions.Execute(_baseSchema.Functions, _compareSchema.Functions);

            //compare packages
            var comparePackages = new ComparePackages(list, _writer);

            comparePackages.Execute(_baseSchema.Packages, _compareSchema.Packages);

            return(list);
        }
コード例 #4
0
        public void WhenTablesIdentical()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareTables(sb, writer);

            var baseTables = new List<DatabaseTable> { CreateTable() };
            var compareTables = new List<DatabaseTable> { CreateTable() };

            //act
            target.Execute(baseTables, compareTables);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(string.IsNullOrEmpty(result));
        }
コード例 #5
0
        public void WhenTablePrimaryKeyChanged()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareTables(sb, writer);

            var baseTables = new List<DatabaseTable> { CreateTable() };
            var table = CreateTable().AddColumn("D", DbType.Int32).Table;
            table.PrimaryKey.Columns.Clear();
            table.PrimaryKey.Columns.Add("D");//the primary key is D, not A
            var compareTables = new List<DatabaseTable> { table };

            //act
            target.Execute(baseTables, compareTables);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD [D] INT"), "add the new column");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] DROP CONSTRAINT [PK_TEST]"), "drop the old pk");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD CONSTRAINT [PK_TEST] PRIMARY KEY ([D])"), "add the new pk");
        }
コード例 #6
0
        public void WhenTableUniqueConstraintChanged()
        {
            //arrange
            var sb = new List<CompareResult>();
            var writer = new ComparisonWriter(SqlType.SqlServer);
            var target = new CompareTables(sb, writer);

            var baseTable = CreateTable();
            baseTable.FindColumn("B").AddUniqueKey("UK_TEST");
            var baseTables = new List<DatabaseTable> { baseTable };
            var compareTable = CreateTable().AddColumn("D", DbType.Int32).Table;
            compareTable.FindColumn("D").AddUniqueKey("UK_TEST");
            var compareTables = new List<DatabaseTable> { compareTable };

            //act
            target.Execute(baseTables, compareTables);
            var result = string.Join(Environment.NewLine, sb.Select(x => x.Script).ToArray());

            //assert
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD [D] INT"), "add the new column");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] DROP CONSTRAINT [UK_TEST]"), "drop the old unique key");
            Assert.IsTrue(result.Contains("ALTER TABLE [Test] ADD CONSTRAINT [UK_TEST] UNIQUE ([D])"), "add the new unique key");
        }