Пример #1
0
        /// alters table, decomposes to alter actions; doesn't transform alter plan
        /// proc must be able to run all logical operations
        public static void DecomposeAlterTable(this IAlterProcessor proc, TableInfo oldTable, TableInfo newTable, DbDiffOptions options)
        {
            DbObjectPairing pairing = CreateTablePairing(oldTable, newTable);
            // decompose to alter actions
            AlterPlan plan = new AlterPlan(oldTable.OwnerDatabase);

            AlterTable(plan, oldTable, newTable, options, pairing);
            var run = plan.CreateRunner();

            run.Run(proc, options);
        }
        public static void AlterDatabase(this IAlterProcessor proc, DatabaseInfo src, DatabaseInfo dst, DatabaseInfo targetDb, DbDiffOptions opts, Action <AlterPlan> extendPlan)
        {
            AlterPlan plan = new AlterPlan(targetDb);

            DbDiffTool.AlterDatabase(plan, src, dst, opts);
            if (extendPlan != null)
            {
                extendPlan(plan);
            }
            plan.Transform(proc.AlterCaps, opts);
            var run = plan.CreateRunner();

            run.Run(proc, opts);
        }
Пример #3
0
        private void TestDiff(Action<DatabaseInfo> mangle, string expectedResult)
        {
            var db1 = new DatabaseInfo();
            var t1 = new TableInfo(db1)
                {
                    Name = "t1",
                    Schema = "dbo",
                };
            t1.Columns.Add(new ColumnInfo(t1)
                {
                    Name = "c1",
                    DataType = "int",
                    NotNull = true,
                    CommonType = new DbTypeInt(),
                });
            t1.Columns.Add(new ColumnInfo(t1)
                {
                    Name = "c2",
                    DataType = "int",
                    NotNull = true,
                    CommonType = new DbTypeInt(),
                });

            var ix = new IndexInfo(t1);
            ix.Columns.Add(new ColumnReference { RefColumn = t1.Columns[0] });
            ix.ConstraintName = "ix1";
            t1.Indexes.Add(ix);

            var pk = new PrimaryKeyInfo(t1);
            pk.Columns.Add(new ColumnReference {RefColumn = t1.Columns[0]});
            pk.ConstraintName = "pk_t1";
            t1.PrimaryKey = pk;

            db1.Tables.Add(t1);

            var v1 = new ViewInfo(db1)
                {
                    Name = "v1",
                    Schema = "dbo",
                    CreateSql = "create view v1 as select * from t1",
                };
            db1.Views.Add(v1);


            var db2 = db1.CloneDatabase();
            mangle(db2);
            var plan = new AlterPlan(db1);
            DbDiffTool.AlterDatabase(plan, db1, db2, new DbDiffOptions());
            var caps = SqlServerDatabaseFactory.Instance.DumperCaps;
            plan.AddLogicalDependencies(caps, new DbDiffOptions());
            plan.Transform(caps, new DbDiffOptions());

            var runner = plan.CreateRunner();
            var sw = new StringWriter();
            var sqlo = new SqlOutputStream(SqlServerDatabaseFactory.Instance.CreateDialect(), sw, new SqlFormatProperties());
            var dmp = SqlServerDatabaseFactory.Instance.CreateDumper(sqlo, new SqlFormatProperties());
            runner.Run(dmp, new DbDiffOptions());
            string sql = sw.ToString();
            Assert.IsNotNull(sql);
            //string expectedTran = TransformSql(expectedResult);
            //string sqlTran = TransformSql(sql);
            //for(int i = 0; i < expectedResult.Length; i++)
            //{
            //    Assert.AreEqual(expectedTran[i], sqlTran[i]);
            //}
            Assert.AreEqual(TransformSql(expectedResult), TransformSql(sql));
        }
Пример #4
0
 public static void AlterDatabase(this IAlterProcessor proc, DatabaseInfo src, DatabaseInfo dst, DatabaseInfo targetDb, DbDiffOptions opts, Action<AlterPlan> extendPlan)
 {
     AlterPlan plan = new AlterPlan(targetDb);
     DbDiffTool.AlterDatabase(plan, src, dst, opts);
     if (extendPlan != null) extendPlan(plan);
     plan.Transform(proc.AlterCaps, opts);
     var run = plan.CreateRunner();
     run.Run(proc, opts);
 }
Пример #5
0
 /// alters table, decomposes to alter actions; doesn't transform alter plan
 /// proc must be able to run all logical operations
 public static void DecomposeAlterTable(this IAlterProcessor proc, TableInfo oldTable, TableInfo newTable, DbDiffOptions options)
 {
     DbObjectPairing pairing = CreateTablePairing(oldTable, newTable);
     // decompose to alter actions
     AlterPlan plan = new AlterPlan(oldTable.OwnerDatabase);
     AlterTable(plan, oldTable, newTable, options, pairing);
     var run = plan.CreateRunner();
     run.Run(proc, options);
 }