Exemplo n.º 1
0
        private void RunMigration(DbMigration migration, bool up)
        {
            var runList = this.GenerateRunList(migration, up);

            if (runList.Count == 0)
            {
                return;
            }

            this.ExecuteWithoutDebug(() =>
            {
                var dba = this.DBA;
                if (runList.Count > 1)
                {
                    /*********************** 代码块解释 *********************************
                     *
                     * 如果执行多句 SQL,则需要主动打开连接,
                     * 否则 DBA 可能会打开之后再把连接关闭,造成多次打开连接,引起分布式事务。
                     * 而分布式事务在一些数据库中并不支持,例如 SQLCE。
                     *
                     **********************************************************************/
                    bool opend = false;
                    var con    = dba.Connection;

                    try
                    {
                        if (con.State != ConnectionState.Open)
                        {
                            con.Open();
                            opend = true;
                        }

                        using (var tran = new TransactionScope())
                        {
                            foreach (var item in runList)
                            {
                                this._currentRun = item as SqlMigrationRun;
                                item.Run(dba);
                            }

                            tran.Complete();
                        }
                    }
                    finally
                    {
                        if (opend)
                        {
                            con.Close();
                        }
                    }
                }
                else
                {
                    var singleRun    = runList[0];
                    this._currentRun = singleRun as SqlMigrationRun;
                    singleRun.Run(dba);
                }
            });
        }
Exemplo n.º 2
0
        private IList <MigrationRun> GenerateRunList(DbMigration migration, bool up)
        {
            migration.DatabaseMetaReader = this.DatabaseMetaReader;

            if (up)
            {
                migration.GenerateUpOperations();
            }
            else
            {
                migration.GenerateDownOperations();
            }

            var runList = _runGenerator.Generate(migration.Operations);

            return(runList);
        }
Exemplo n.º 3
0
 private void MigrateDown(DbMigration migration)
 {
     this.RunMigration(migration, false);
 }
Exemplo n.º 4
0
 private void MigrateUp(DbMigration migration)
 {
     this.RunMigration(migration, true);
 }
Exemplo n.º 5
0
        private void RunMigration(DbMigration migration, bool up)
        {
            var runList = this.GenerateRunList(migration, up);

            if (runList.Count == 0) return;

            this.ExecuteWithoutDebug(() =>
            {
                var dba = this.DBA;
                if (runList.Count > 1)
                {
                    /*********************** 代码块解释 *********************************
                     *
                     * 如果执行多句 SQL,则需要主动打开连接,
                     * 否则 DBA 可能会打开之后再把连接关闭,造成多次打开连接,引起分布式事务。
                     * 而分布式事务在一些数据库中并不支持,例如 SQLCE。
                     *
                    **********************************************************************/
                    bool opend = false;
                    var con = dba.Connection;

                    try
                    {
                        if (con.State != ConnectionState.Open)
                        {
                            con.Open();
                            opend = true;
                        }

                        using (var tran = new TransactionScope())
                        {
                            foreach (var item in runList)
                            {
                                this._currentRun = item as SqlMigrationRun;
                                item.Run(dba);
                            }

                            tran.Complete();
                        }
                    }
                    finally
                    {
                        if (opend)
                        {
                            con.Close();
                        }
                    }
                }
                else
                {
                    var singleRun = runList[0];
                    this._currentRun = singleRun as SqlMigrationRun;
                    singleRun.Run(dba);
                }
            });
        }
Exemplo n.º 6
0
 private void MigrateUp(DbMigration migration)
 {
     this.RunMigration(migration, true);
 }
Exemplo n.º 7
0
 private void MigrateDown(DbMigration migration)
 {
     this.RunMigration(migration, false);
 }
Exemplo n.º 8
0
        private IList<MigrationRun> GenerateRunList(DbMigration migration, bool up)
        {
            migration.DatabaseMetaReader = this.DatabaseMetaReader;

            if (up)
            {
                migration.GenerateUpOperations();
            }
            else
            {
                migration.GenerateDownOperations();
            }

            var runList = this._runGenerator.Generate(migration.Operations);

            return runList;
        }