示例#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.");
         if (!string.IsNullOrEmpty(_outDiff)) {
             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
        private static void TestCompare(Database source, Database copy)
        {
            //compare the dbs to make sure they are the same
            Assert.IsFalse(source.Compare(copy).IsDiff);

            // get a second opinion
            // if you ever find your license key
            /*
                        var cmd = string.Format("/c {0}\\SQLDBDiffConsole.exe {1} {2} {0}\\{3}",
                            ConfigHelper.SqlDbDiffPath,
                            "localhost\\SQLEXPRESS " + copy.Name + " NULL NULL Y",
                            "localhost\\SQLEXPRESS " + source.Name + " NULL NULL Y",
                            "SqlDbDiff.XML CompareResult.txt null");

                        Console.WriteLine(cmd);
                        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]);
            */
        }
示例#3
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]);
        }
示例#4
0
        public void TestScriptDeletedProc()
        {
            var source = new Database();
            source.Routines.Add(new Routine("dbo", "test"));
            source.FindRoutine("test", "dbo").RoutineType = Routine.RoutineKind.Procedure;
            source.FindRoutine("test", "dbo").Text = @"
            create procedure [dbo].[test]
            as
            select * from Table1
            ";

            var target = new Database();
            string scriptUp = target.Compare(source).Script();
            string scriptDown = source.Compare(target).Script();
            Assert.IsTrue(scriptUp.ToLower().Contains("drop procedure [dbo].[test]"));
            Assert.IsTrue(scriptDown.ToLower().Contains("create procedure [dbo].[test]"));
        }