public Compare ( |
||
db | ||
Résultat |
public bool Execute() { var sourceDb = new Database(); var targetDb = new Database(); sourceDb.Connection = Source; targetDb.Connection = Target; sourceDb.Load(); targetDb.Load(); var 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)) { var message = string.Format( "{0} already exists - set overwrite to true if you want to delete it", OutDiff); throw new InvalidOperationException(message); } File.WriteAllText(OutDiff, diff.Script()); Console.WriteLine("Script to make the databases identical has been created at {0}", Path.GetFullPath(OutDiff)); } return true; } Console.WriteLine("Databases are identical."); return false; }
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]); */ }
public void TestDiffScript() { TestHelper.DropDb("TEST_SOURCE"); TestHelper.DropDb("TEST_COPY"); //create the dbs from sql script var 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 var diff = copy.Compare(source); TestHelper.ExecBatchSql(diff.Script(), "TEST_SOURCE"); //compare the dbs to make sure they are the same var 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]); }
public void TestScriptDeletedProc() { var source = new Database(); source.Routines.Add(new Routine("dbo", "test", null)); 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(); var scriptUp = target.Compare(source).Script(); var scriptDown = source.Compare(target).Script(); Assert.IsTrue(scriptUp.ToLower().Contains("drop procedure [dbo].[test]")); Assert.IsTrue(scriptDown.ToLower().Contains("create procedure [dbo].[test]")); }