Compare() 공개 메소드

public Compare ( Table t ) : TableDiff
t Table
리턴 TableDiff
예제 #1
0
		public void TestCompare() {
			var t1 = new Table("dbo", "Test");
			var t2 = new Table("dbo", "Test");
			var diff = default(TableDiff);

			//test equal
			t1.Columns.Add(new Column("first", "varchar", 30, false, null));
			t2.Columns.Add(new Column("first", "varchar", 30, false, null));
			t1.AddConstraint(new Constraint("PK_Test", "PRIMARY KEY", "first"));
			t2.AddConstraint(new Constraint("PK_Test", "PRIMARY KEY", "first"));

			diff = t1.Compare(t2);
			Assert.IsNotNull(diff);
			Assert.IsFalse(diff.IsDiff);

			//test add
			t1.Columns.Add(new Column("second", "varchar", 30, false, null));
			diff = t1.Compare(t2);
			Assert.IsTrue(diff.IsDiff);
			Assert.AreEqual(1, diff.ColumnsAdded.Count);

			//test delete
			diff = t2.Compare(t1);
			Assert.IsTrue(diff.IsDiff);
			Assert.AreEqual(1, diff.ColumnsDropped.Count);

			//test diff
			t1.Columns.Items[0].Length = 20;
			diff = t1.Compare(t2);
			Assert.IsTrue(diff.IsDiff);
			Assert.AreEqual(1, diff.ColumnsDiff.Count);

			Console.WriteLine("--- create ----");
			Console.Write(t1.ScriptCreate());

			Console.WriteLine("--- migrate up ---");
			Console.Write(t1.Compare(t2).Script());

			Console.WriteLine("--- migrate down ---");
			Console.Write(t2.Compare(t1).Script());
		}
예제 #2
0
		public void CompareConstraints() {

			var t1 = new Table("dbo", "Test");
			var t2 = new Table("dbo", "Test");
			var diff = default(TableDiff);

			//test equal
			t1.Columns.Add(new Column("first", "varchar", 30, false, null));
			t2.Columns.Add(new Column("first", "varchar", 30, false, null));
			t1.AddConstraint(Constraint.CreateCheckedConstraint("IsTomorrow", true, "fnTomorrow()"));
			t2.AddConstraint(Constraint.CreateCheckedConstraint("IsTomorrow", false, "Tomorrow <> 1"));

			diff = t1.Compare(t2);
			Assert.AreEqual(1, diff.ConstraintsChanged.Count);
			Assert.IsNotNull(diff);
			Assert.IsTrue(diff.IsDiff);

		}