@param Migration $migration
@param bool $useTransaction
@throws \Exception

@todo add support for adminLogin ?
431888
public function resumeMigration(Migration $migration, $useTransaction = true)
    {
        if ($migration->status != Migration::STATUS_SUSPENDED) {
            throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': it is not in suspended status");
        }

        $migrationDefinitions = $this->getMigrationsDefinitions(array($migration->path));
        if (!count($migrationDefinitions)) {
            throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': its definition is missing");
        }

        $defs = $migrationDefinitions->getArrayCopy();
        $migrationDefinition = reset($defs);

        $migrationDefinition = $this->parseMigrationDefinition($migrationDefinition);
        if ($migrationDefinition->status == MigrationDefinition::STATUS_INVALID) {
            throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': {$migrationDefinition->parsingError}");
        }

        // restore context
        $this->contextHandler->restoreCurrentContext($migration->name);

        if (!isset($this->migrationContext[$migration->name])) {
            throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': the stored context is missing");
        }
        $restoredContext = $this->migrationContext[$migration->name];
        if (!is_array($restoredContext) || !isset($restoredContext['context']) || !isset($restoredContext['step'] )) {
            throw new \Exception("Can not resume ".$this->getEntityName($migration)." '{$migration->name}': the stored context is invalid");
        }

        // update migration status
        $migration = $this->storageHandler->resumeMigration($migration);

        // clean up restored context - ideally it should be in the same db transaction as the line above
        $this->contextHandler->deleteContext($migration->name);

        // and go
        // note: we store the current step counting starting at 1, but use offset starting at 0, hence the -1 here
        $this->executeMigrationInner($migration, $migrationDefinition, $restoredContext['context'],
            $restoredContext['step'] - 1, $useTransaction);
    }
515070
public function addMigration(SQLMigration $migration) {
		if (!$migration instanceof MySQLMigration) {
			throw new InvalidMigrationType(\get_class($migration));
		}
		$this->migrations[\get_class($migration)] = $migration;
	}
249212
public function insert(Migration $migration)
    {
        $fileName = $this->_getFileName($migration);
        if (is_file($fileName)) {
            throw new \InvalidArgumentException(__METHOD__.": Migration file `{$migration->getName()}` exists");
        }

        file_put_contents($fileName, $migration->getSql());
    }
1186936
public function transAlterField($table, $field, $schema)
    {
        $this->transInitTable($table);
        $this->schemaUpdateTransaction[$table]['alteredFields'][$field] = $schema;
    }
391786
public function runPending(array $migrations, array $options = [])
    {
        // First we will just make sure that there are any migrations to run. If there
        // aren't, we will just make a note of it to the developer so they're aware
        // that all of the migrations have been run against this database system.
        if (count($migrations) == 0) {
            $this->note('<info>Nothing to migrate.</info>');

            return;
        }

        foreach ($migrations as $file) {
            $this->runUp($file);
        }
    }
1314907
protected function runDown($file, $migration)
    {
        $file     = $this->migrator->getMigrationName($file);
        $instance = $this->migrator->resolve($file);

        $instance->down();

        $this->migrator->getRepository()->delete($migration);

        $this->info("Rolledback: ".$file);
    }
340592
public function run(MigrationContext $context)
	{
		$this->setContext($context);
		$this->createMigrationsTable();

		$all_migrations = $this->getAllMigrations();
		$executed_migrations = $this->getExecutedMigrations();

		$migrations_to_execute = array_diff($all_migrations, $executed_migrations);
		$this->executeMigrations($migrations_to_execute);

		$migrations_to_delete = array_diff($executed_migrations, $all_migrations);
		$this->deleteMigrations($migrations_to_delete);
	}
118066
private function isMigrated($migration, OutputInterface $output = null)
    {
        if ($this->_db->schema()->hasTable('migrations')) {
            $table = $this->_cap->table('migrations');
            $m = $table->where('migration', '=', $migration);
            if ($m->count() > 0) {
                $item = $m->first();
                if ($item->migrated == 1) {
                    return true;
                }
            }
        } else {
            $this->createMigrationsTable($output);

            return $this->isMigrated($migration);
        }

        return false;
    }
946181
protected function executeMigrations(array $migrations)
	{
		if ( !$migrations ) {
			return;
		}

		$db = $this->_context->getDatabase();

		foreach ( $migrations as $migration ) {
			$db->beginTransaction();
			$migration_type = pathinfo($migration, PATHINFO_EXTENSION);

			$this->_migrationRunners[$migration_type]->run(
				$this->_migrationsDirectory . '/' . $migration,
				$this->_context
			);

			$sql = 'INSERT INTO Migrations (Name, ExecutedOn)
					VALUES (:name, :executed_on)';
			$db->perform($sql, array('name' => $migration, 'executed_on' => time()));
			$db->commit();
		}
	}
969672
protected function runMigration($migrateController, $command)
    {
        $filter = stream_filter_prepend(STDOUT, "block_stdout");
        ob_start();
        ob_implicit_flush();

        $migrateController->runAction($command);

        ob_clean();
        stream_filter_remove($filter);
    }
633865
protected function importMigration(Migration $migration) {
    // Run dependencies first.
    $dependencies = $migration->getMigrationDependencies();
    $required_ids = $dependencies['required'];
    if ($required_ids) {
      $required_migrations = $this->migrationManager->createInstances($required_ids);
      array_walk($required_migrations, [$this, 'importMigration']);
    }

    $message = new MigrateMessage();
    $executable = new MigrateExecutable($migration, $message);
    $executable->import();
  }
1327279
public void withVoidTransaction(@NotNull TransactionSettings settings,
                                    @NotNull VoidTransactionCallback callback) {
        withTransaction(settings, fromVoidCallback(callback));
    }
502893
protected function runMigration($migration, $method)
    {
        $callback = function () use ($migration, $method) {
            if (method_exists($migration, $method)) {
                $migration->{$method}();
            }
        };

        $callback();
    }
1346008
public static function startTransaction(callable $callback = null)
    {
        static::verifyConnection();

        if (!static::$adapter->getConnection()->inTransaction()) {
            static::$adapter->getConnection()->beginTransaction();
        }

        if (is_callable($callback)) {
            try {
                call_user_func_array($callback, []);

                static::commit();
            } catch (DatabaseException $e) {
                static::rollback();
            }
        }
    }
954061
private function makeUp($current_migrations, $migrations)
    {
        if (count($current_migrations) == count($migrations)) {
            echo Color::green('Nothing to migrate.');
            
            return;
        }

        foreach ($migrations as $file => $migration) {
            if ($this->checkMigrationExistance($migration)) {
                continue;
            }

            // Include the migration file
            require $file;

            try {
                // Up migration
                (new $migration)->up();
            } catch (\Exception $exception) {
                $this->throwMigrationException($exception, $migration);
            }

            // Create new migration status
            $this->createMigrationStatus($migration);
        }

        foreach ($current_migrations as $migration) {
            $this->updateMigrationStatus(
                $migration->migration,
                $migration->batch + 1
            );
        }
    }
391244
private function updateMigrationStatus($migration, $batch)
    {
        $table = $this->getMigrationTable();

        return $table->where('migration', $migration)->update([
            'migration' => $migration,
            'batch' => $batch
        ]);
    }
294182
public function setTransactionIsolation($isolation)
    {
        if (!$this->getPlatform()->supportTransactionIsolations()) {
            throw ConnectionException::transactionIsolationNotSupported();
        }

        $this->executeUpdate($this->getPlatform()->getSetTransactionIsolationSQLQuery($isolation));
        $this->transactionIsolation = $isolation;
    }