示例#1
0
        public override int Run(string[] remainingArguments)
        {
            var sourceDb = new Database();
            var targetDb = new Database();

            sourceDb.Connection = _source;
            targetDb.Connection = _target;
            sourceDb.Load();
            targetDb.Load();
            DatabaseDiff diff = sourceDb.Compare(targetDb);

            if (diff.IsDiff)
            {
                Console.WriteLine("Databases are different.");
                Console.WriteLine(diff.SummarizeChanges(_verbose));
                if (!string.IsNullOrEmpty(_outDiff))
                {
                    Console.WriteLine();
                    if (!_overwrite && File.Exists(_outDiff))
                    {
                        if (!ConsoleQuestion.AskYN(string.Format("{0} already exists - do you want to replace it", _outDiff)))
                        {
                            return(1);
                        }
                    }
                    File.WriteAllText(_outDiff, diff.Script());
                    Console.WriteLine("Script to make the databases identical has been created at {0}", Path.GetFullPath(_outDiff));
                }
                return(1);
            }
            Console.WriteLine("Databases are identical.");
            return(0);
        }
示例#2
0
        public void TestDiffScript()
        {
            TestHelper.DropDb("TEST_SOURCE");
            TestHelper.DropDb("TEST_COPY");

            //create the dbs from sql script
            string script = File.ReadAllText(ConfigHelper.TestSchemaDir + "\\BOP_QUOTE.sql");

            TestHelper.ExecSql("CREATE DATABASE TEST_SOURCE", "");
            TestHelper.ExecBatchSql(script, "TEST_SOURCE");

            script = File.ReadAllText(ConfigHelper.TestSchemaDir + "\\BOP_QUOTE_2.sql");
            TestHelper.ExecSql("CREATE DATABASE TEST_COPY", "");
            TestHelper.ExecBatchSql(script, "TEST_COPY");

            var source = new Database("TEST_SOURCE");

            source.Connection = TestHelper.GetConnString("TEST_SOURCE");
            source.Load();

            var copy = new Database("TEST_COPY");

            copy.Connection = TestHelper.GetConnString("TEST_COPY");
            copy.Load();

            //execute migration script to make SOURCE the same as COPY
            DatabaseDiff diff = copy.Compare(source);

            TestHelper.ExecBatchSql(diff.Script(), "TEST_SOURCE");

            //compare the dbs to make sure they are the same
            string cmd = string.Format("/c {0}\\SQLDBDiffConsole.exe {1} {2} {0}\\{3}", ConfigHelper.SqlDbDiffPath,
                                       "localhost\\SQLEXPRESS TEST_COPY   NULL NULL Y", "localhost\\SQLEXPRESS TEST_SOURCE NULL NULL Y",
                                       "SqlDbDiff.XML CompareResult.txt null");
            var proc = new Process();

            proc.StartInfo.FileName    = "cmd.exe";
            proc.StartInfo.Arguments   = cmd;
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            proc.Start();
            proc.WaitForExit();

            Assert.AreEqual("no difference", File.ReadAllLines("CompareResult.txt")[0]);
        }