Inheritance: IComparable
Ejemplo n.º 1
0
 public virtual MigrationTracker RecordMigration(Migration migration)
 {
     if (!MigrationTableExists())
     {
         Init();
     }
     connection.Open();
     var cmd = GetMigrationCmd(migration);
     cmd.ExecuteNonQuery();
     connection.Close();
     return Create();
 }
Ejemplo n.º 2
0
 protected abstract IDbCommand GetMigrationCmd(Migration migration);
Ejemplo n.º 3
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))
             {
                 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();
 }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
 public MigrationException(Migration migration, MigrationDirection direction,  Exception ex)
 {
     this.migration = migration;
     this.direction = direction;
     this.ex = ex;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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();
        }