Run migration from app config
@param string $command either `up` or `down`
966195
protected function runMigrationByApplication($command)
    {
        $app = $this->mockApplication();

        list($migrateController, $route) = $app->createController('migrate');

        if ($migrateController === null) {
            throw new ExtensionException(
              __CLASS__,
              "At least one of `migrationPath` or `migrationNamespaces` should be specified.\nOr describe migrations in your app config."
            );
        }

        if ($migrateController->interactive) {
            $this->writeln('Cannot run the migrate interactively, the interaction was disabled.');
            $migrateController->interactive = false;
        }

        $this->runMigration($migrateController, $command);

        $this->destroyApplication();
    }
1122396
public function dispatch($command): void
    {
        $this->commandQueue[] = $command;

        if (! $this->isDispatching) {
            $this->isDispatching = true;

            $actionEventEmitter = $this->events;

            try {
                while ($command = \array_shift($this->commandQueue)) {
                    $actionEvent = $actionEventEmitter->getNewActionEvent(
                        self::EVENT_DISPATCH,
                        $this,
                        [
                            self::EVENT_PARAM_MESSAGE => $command,
                        ]
                    );

                    try {
                        $actionEventEmitter->dispatch($actionEvent);

                        if (! $actionEvent->getParam(self::EVENT_PARAM_MESSAGE_HANDLED)) {
                            throw new RuntimeException(\sprintf('Command %s was not handled', $this->getMessageName($command)));
                        }
                    } catch (\Throwable $exception) {
                        $actionEvent->setParam(self::EVENT_PARAM_EXCEPTION, $exception);
                    } finally {
                        $actionEvent->stopPropagation(false);
                        $this->triggerFinalize($actionEvent);
                    }
                }
                $this->isDispatching = false;
            } catch (\Throwable $e) {
                $this->isDispatching = false;
                throw CommandDispatchException::wrap($e, $this->commandQueue);
            }
        }
    }
1320983
public function handle(MigrateMessage $command)
    {
        $input = $command->getInput();
        $output = $command->getOutput();
        $this->command = $command;

        $targetArg = (string) $input->getArgument(MigrateMessage::ARG_TARGET);
        $strategy = (string) $this->getStrategyOption($input);

        $options = new Options(Options::DIRECTION_UP); // this value will get replaced by timeline later
        $options->setDryRun($input->getOption(MigrateMessage::OPT_DRY_RUN));
        $options->setExceptionOnSkip(false);

        $this->saveChanges = !$input->getOption(MigrateMessage::OPT_NO_STORAGE) && !$options->isDryRun();

        $this->trackProgress = ($output->getVerbosity() !== OutputInterface::VERBOSITY_QUIET)
            && !$input->getOption(MigrateMessage::OPT_NOPROGRESS);

        $this->attachEvents($output, $command->getTimeline()->getEventDispatcher());

        /* @var \Baleen\Migrations\Version\Collection\LinkedVersions $results */
        $command->getTimeline()->$strategy($targetArg, $options);
    }
793250
public function run(string $path): void
    {
        // We need to make sure migration table is available.
        $this->createMigrationRepository();

        $this->migrator->run($path);
    }
280038
protected function registerAddonStatusCommand($command)
    {
        $this->app->singleton($command, function ($app) {
            return new Addons\Commands\AddonStatusCommand($app);
        });
    }
987635
private function _run($command) 
	{
		if ($this->options['type'] === self::TYPE_PHP) {
			// Old Option: Run direct from terminal (doesn't like brackets too much).
			// $cmd = "php -r \"{$command}\"";

			// New Option: Save to temp file & run it.
			$this->savedFiles[] = $this->options['tmp-dir'] . 'async-tmp-' . time() . '.php';
			$result = file_put_contents(
				end($this->savedFiles),
				$this->_generateCode($command),
				LOCK_EX
			);

			if ($result !== false) {
				$cmd = "php " . end($this->savedFiles);
			}
			else {
				$cmd = "php --help";
			}
		}
		else {
			$cmd = $command;
		}

		if ($this->options['async']) {
			// This forks the process.
			// Helpful guide @ https://segment.com/blog/how-to-make-async-requests-in-php/
			$cmd .= ' > /dev/null 2>&1 &';
		}

		exec($cmd, $output, $exit);

		if ($this->options['debug']) {
			echo '<br />Command Run: ' . $cmd;
		}

		return $exit === 0;
	}
1116491
public static function prepareMigrationTable(App $app): void{
        $migration = new class($app) extends Migration{

            /**
             * Create the migration table if it does not exist yet
             */
            public function up(): void{
                $schema = $this->getSchema('default');
                if (!$schema->hasTable('migrations')) {
                    $schema->create('migrations', function (Blueprint $table){
                        $table->increments('id');
                        $table->string('name', 255);
                    });
                }
            }

            /**
             * Is not needed, but add it nevertheless
             */
            public function down(): void{
                $this->getSchema('default')->drop('migrations');
            }
        };
        $migration->up();
    }
437824
protected function sendCommandToServer(string $command): void
	{
		$this->lastCommand = $command;

		$this->connection->write($command);
	}
1365839
protected function execute($command)
    {
        $process = new Process($command);
        $process->setTimeout(null);
        $process->run();

        if (!$process->isSuccessful()) {
            throw new \RuntimeException($process->getErrorOutput());
        }
    }
1170245
public function run_command($command) {
        \Log::debug($command);

        $descriptorspec = array(
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w'),
        );
        $pipes = array();
        /* Depending on the value of variables_order, $_ENV may be empty.
         * In that case, we have to explicitly set the new variables with
         * putenv, and call proc_open with env=null to inherit the reset
         * of the system.
         *
         * This is kind of crappy because we cannot easily restore just those
         * variables afterwards.
         *
         * If $_ENV is not empty, then we can just copy it and be done with it.
         */
        if(count($_ENV) === 0) {
            $env = NULL;
            foreach($this->envopts as $k => $v) {
                putenv(sprintf("%s=%s",$k,$v));
            }
        } else {
            $env = array_merge($_ENV, $this->envopts);
        }
        $cwd = $this->repo_path;
        $resource = proc_open($command, $descriptorspec, $pipes, $cwd, $env);

        $stdout = stream_get_contents($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        foreach ($pipes as $pipe) {
            fclose($pipe);
        }

        $status = trim(proc_close($resource));
        if ($status) throw new Exception($stderr);

        return $stdout;
    }
1298598
public function runSingleCommand($command)
    {
        $cmd = 'php ' . $this->directory . 'app/console ';

        return $this->phpci->executeCommand($cmd . $command, $this->directory);
    }
834187
public function execute($command, callable $next)
    {
        $migration = $command->getMigration();
        if (!$migration instanceof TransactionAwareInterface) {
            $next($command);
            return;
        }

        $result = null;
        try {
            $migration->begin();
            $next($command);
            $migration->finish();
        } catch (\Exception $e) {
            $migration->abort($e);
        }
    }
1359322
public function enable(Command $command)
    {
        $command->call('down');

        foreach ($this->scripts as $script) {
            try {
                $this->app->make($script)->fire($command);
            } catch (\Exception $e) {
                $command->error($e->getMessage());

                return false;
            }
        }

        $command->call('up');

        return true;
    }
1282737
public function execUp(string $name): void{
        DB::connection('default')->table('migrations')->insert(['name' => $name]);
        $this->up();
    }
1079062
protected function forceCommand($command)
    {
        return (
            starts_with($command, 'migrate') === true && starts_with($command, 'migrate:status') === false ||
            starts_with($command, 'db:seed') === true
        ) && strpos('command', '--force') === false ?
            $command .= ' --force' : $command;
    }
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);
    }
1243816
public function dispatch($command): void
    {
        $this->commandStack[] = $command;

        if ($this->executing) {
            return;
        }

        $this->transactionManager->begin();
        try {
            while ($command = array_shift($this->commandStack)) {
                $this->invokeHandler($command);
            }
            $this->eventPublisher->publishEvents();
            $this->transactionManager->commit();
        } catch (Exception $e) {
            $this->transactionManager->rollback();
            throw $e;
        }
    }