Inheritance: IComparable
 public virtual MigrationTracker RecordMigration(Migration migration)
 {
     if (!MigrationTableExists())
     {
         Init();
     }
     connection.Open();
     var cmd = GetMigrationCmd(migration);
     cmd.ExecuteNonQuery();
     connection.Close();
     return Create();
 }
 protected abstract IDbCommand GetMigrationCmd(Migration migration);
 public virtual MigrationTracker ExecuteUp(Migration migration)
 {
     if (!MigrationTableExists())
         Init();
     connection.Open();
     using (var trans = connection.BeginTransaction(IsolationLevel.ReadUncommitted))
     {
         var split = new Regex(delimiter, RegexOptions.Multiline | RegexOptions.IgnoreCase);
         var statements = split.Split(migration.UpSql);
         foreach (var sql in statements)
         {
             if (!string.IsNullOrWhiteSpace(sql))
             {
                 var cmd = connection.CreateCommand();
                 cmd.Transaction = trans;
                 cmd.CommandText = sql;
                 cmd.ExecuteNonQuery();
             }
         }
         IDbCommand migrationCmd = GetMigrationCmd(migration);
         migrationCmd.Transaction = trans;
         migrationCmd.ExecuteNonQuery();
         trans.Commit();
     }
     connection.Close();            ;
     return Create();
 }
        public virtual MigrationTracker ExecuteDown(Migration migration)
        {
            if (!MigrationTableExists())
                Init();
            connection.Open();
            using (var trans = connection.BeginTransaction())
            {
                var split = new Regex(delimiter, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                foreach (var sql in split.Split(migration.DownSql))
                {
                    if (!string.IsNullOrEmpty(sql))
                    {
                        var cmd = connection.CreateCommand();
                        cmd.Transaction = trans;
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                    }
                }

                var migrationCmd = connection.CreateCommand();
                migrationCmd.Transaction = trans;
                migrationCmd.CommandText = string.Format("delete from {0} where [key] = @version", tableName);
                var version = migrationCmd.CreateParameter();
                version.ParameterName = "version";
                version.Value = migration.Version;
                migrationCmd.Parameters.Add(version);
                migrationCmd.ExecuteNonQuery();
                trans.Commit();
            }
            connection.Close();
            return Create();
        }
示例#5
0
 public MigrationException(Migration migration, MigrationDirection direction,  Exception ex)
 {
     this.migration = migration;
     this.direction = direction;
     this.ex = ex;
 }
示例#6
0
 protected override IDbCommand GetMigrationCmd(Migration migration)
 {
     var migrationCmd = (SqlCommand)connection.CreateCommand();
     migrationCmd.CommandText = string.Format("insert into {0} VALUES(@key, @hash)", tableName);
     migrationCmd.Parameters.AddWithValue("@key", migration.Version);
     migrationCmd.Parameters.AddWithValue("@hash", migration.Hash);
     return migrationCmd;
 }
示例#7
0
        public virtual MigrationTracker ExecuteUp(Migration migration)
        {
            if (!MigrationTableExists())
                Init();

            connection.Open();

            using (var trans = connection.BeginTransaction(IsolationLevel.ReadUncommitted))
            {
                var split = new Regex(delimiter, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                var statements = split.Split(migration.UpSql);

                foreach (var sql in statements)
                {
                    if (string.IsNullOrWhiteSpace(sql))
                        continue;

                    try
                    {
                        var cmd = connection.CreateCommand();
                        cmd.Transaction = trans;
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception)
                    {
                        System.Diagnostics.Debug.WriteLine("Fail executing sql -> {0}", sql);
                        throw;
                    }

                }

                var migrationCmd = GetMigrationCmd(migration);
                migrationCmd.Transaction = trans;
                migrationCmd.ExecuteNonQuery();
                trans.Commit();
            }

            connection.Close();            ;

            return Create();
        }