Run "up" a migration instance.

@param  string  $file
@param  int     $batch
@param  bool    $pretend

@return void
345707
protected function runUp($file, $batch, $pretend)
    {
        $file = $this->getMigrationName($file);

        // First we will resolve a "real" instance of the migration class from this
        // migration file name. Once we have the instances we can run the actual
        // command such as "up" or "down", or we can just simulate the action.
        $migration = $this->resolve($file);

        if ($pretend) {
            $this->pretendToRun($migration, 'up');

            return;
        }

        $migration->up($key = $this->entity->getKey(), $this->entity);

        // Once we have run a migrations class, we will log that it was run in this
        // repository so that we don't try to run it next time we do a migration
        // in the application. A migration repository keeps the migrate order.
        $this->repository->log($file, $batch);

        $this->note("<info>Migrated [{$this->entity->getTable()}:{$key}]:</info> {$file}");
    }
480481
public function loadDatabase(string $file): void
	{
		$this->connection->transactional(function (Connection $db) use ($file) {
			$db->query('SET foreign_key_checks = 0');
			FileImporter::executeFile($db, $file);
			$db->query('SET foreign_key_checks = 1');
		});
	}
675351
protected function up($className)
    {
        if ($fileName = $this->migrated($className)) {
            $migration = new $className;
            $migration->up();
            $migration->execute();

            $this->connection->insert("schema_migrations", [
                'version' => $fileName,
                'date'    => date("Y-m-d")
            ]);
        }
    }
1075508
public function copyToAppliedDir($file)
    {
        if (false === @copy($file->getPathName(), $this->appliedFilesDir . '/' . $file->getFileName())) {
            throw new RuntimeException('cannot copy the sql file to applied directory. check the <info>'. $this->appliedFilesDir . '</info> directory.');
        }
    }
987077
protected function runDeploy($file)
    {
        $deploy = $this->resolve($name = $this->getDeployName($file));

        $this->note("<comment>Deploying:</comment> {$name}");

        // Run deploy
        $deploy->run();

        $this->note("<info>Deployed:</info>  {$name}");
    }
33579
public function run($migration_file, MigrationContext $context)
	{
		$sqls = file_get_contents($migration_file);
		$sqls = array_filter(preg_split('/;\s+/', $sqls));

		if ( !$sqls ) {
			throw new \LogicException('The "' . basename($migration_file) . '" migration contains no SQL statements.');
		}

		$db = $context->getDatabase();

		foreach ( $sqls as $sql ) {
			$db->perform($sql);
		}
	}
501901
public function requireFile($file, $return = false)
    {
        if($this->findFile($file)) {
            if($return !== false) {
                return require($file);
            }
            else {
                require($file);
            }
        }
        else {
            throw new Exception($file." file is missing.");
            exit;
        }
    }
806383
public function loadDatabase(string $file): void
	{
		Helpers::loadFromFile($this->context->getConnection(), $file);
	}
1054972
public function move($up)
    {
        $table = $this->getTableName();

        if ($up && ($this->position > 1)) {
            $this->position--;
            $this->app['redbean']->exec('UPDATE '.$table.' SET position = position + 1 WHERE position = ?', [$this->position]);
        } else if (!$up && ($this->position < $this->app['redbean']->count($table))) {
            $this->position++;
            $this->app['redbean']->exec('UPDATE '.$table.' SET position = position - 1 WHERE position = ?', [$this->position]);
        }
    }
231656
protected function runUp($file, $batch, $pretend)
	{
           
		// First we will resolve a "real" instance of the migration class from this
		// migration file name. Once we have the instances we can run the actual
		// command such as "up" or "down", or we can just simulate the action.
		$migration = $this->resolve($file);

		if ($pretend)
		{
			return $this->pretendToRun($migration, 'up');
		}

		$migration->up();
                

		// Once we have run a migrations class, we will log that it was run in this
		// repository so that we don't try to run it next time we do a migration
		// in the application. A migration repository keeps the migrate order.
		$this->repository->log($file, $batch);

		$this->note("<info>Migrated:</info> $file");
	}
283705
protected function runSteps($steps = [], $pretend = false)
    {
        $return = true;
        $steps  = empty($steps) ? array_keys($this->steps) : $steps;

        foreach ($steps as $step)
        {
            if ($this->runStep($step, $pretend) === false)
            {
                $return = false;
            }
        }

        return $return;
    }
201783
public function migrate($version = null)
    {
        $migrations     = $this->getMigrations();
        $versions       = $this->getVersions();
        $currentVersion = $this->getCurrentVersion();

        if (!count($migrations)) {
            throw new \RuntimeException('No migrations found.');
        }

        if ($version === null) {
            $version = max(array_merge($versions, array_keys(iterator_to_array($migrations))));
        } else {
            if ($version != 0 && empty($migrations[$version])) {
                throw new \RuntimeException('Version is not valid.');
            }
        }

        // Prepare SQL logs
        if (is_file($this->getLogFile())) {
            File::delete($this->getLogFile());
        }

        Folder::create(dirname($this->getLogFile()));

        $queryLogStream = new Stream($this->getLogFile(), Stream::MODE_WRITE_ONLY_FROM_END);
        $logListener = function (Event $event) use ($queryLogStream) {
            $queryLogStream->write($event['query'] . ";\n\n");
        };
        Ioc::getDispatcher()->listen('onMigrationAfterQuery', $logListener);

        $direction = ($version > $currentVersion) ? AbstractMigration::UP : AbstractMigration::DOWN;

        $migrations = iterator_to_array($migrations);

        $count = 0;

        try {
            if ($direction === AbstractMigration::DOWN) {
                krsort($migrations);

                foreach ($migrations as $migration) {
                    if ($migration['version'] <= $version) {
                        break;
                    }

                    if (in_array($migration['version'], $versions)) {
                        $this->executeMigration($migration, AbstractMigration::DOWN);
                    }

                    $count++;
                }
            }

            ksort($migrations);

            foreach ($migrations as $migration) {
                if ($migration['version'] > $version) {
                    break;
                }

                if (!in_array($migration['version'], $versions, true)) {
                    $this->executeMigration($migration, AbstractMigration::UP);
                }

                $count++;
            }
        } catch (\PDOException $e) {
            $queryLogStream->write("-- ERROR: {$e->getMessage()}\n" . $this->db->getQuery());

            throw $e;
        }

        Ioc::getDispatcher()->removeListener($logListener);

        if (!$count) {
            $this->out('No change.');
        }
    }
810332
public function executeScript(Database $db, $file)
    {
        $scripts = $this->configuration->getMigrationsScriptDirectory();
        if (null === $scripts) {
            throw new \RuntimeException('Missing Configuration for migrations script directory');
        }

        $path = realpath($scripts . '/' . $file);
        if (!file_exists($path)) {
            throw new \InvalidArgumentException(sprintf('Could not execute %s. File does not exist.', $path));
        }

        try {
            $js = file_get_contents($path);
            if (false === $js) {
                throw new \Exception('file_get_contents returned false');
            }
        } catch (\Exception $e) {
            throw $e;
        }

        $result = $db->command(['$eval' => $js, 'nolock' => true]);

        if (isset($result['errmsg'])) {
            throw new \Exception($result['errmsg'], isset($result['errno']) ? $result['errno'] : null);
        }

        return $result;
    }
514381
public static function start(String $file)
    {
        if( ! Info::available($file) )
        {
            throw new Exception\FileNotFoundException($file);
        }

        self::readFileContent($file);
    }
117409
def do_up(self, arg):
        """"""
        print "running up migration"
        self.manager.run(arg, Direction.UP)
1002784
public function apply()
    {

        $files = $this->getMigrationsFiles();
        $lastMigration = null;

        asort($files);

        foreach ($files as $key => $value) {
            if ($key <= $this->getVersion()) continue;
            include $this->migrateManager->storagePath . '/' . $value;
            $className = "Migration_$key";
            $class = new $className();
            $class->up();
            $lastMigration = $key;
            unset($class);
        }

        if (!is_null($lastMigration)) {
            $this->setVersion($lastMigration);
            echo Utils::colorize("Done!", "SUCCESS");
        } else {
            echo Utils::colorize("The latest version is already installed.", "NOTE");
        }

    }
153904
protected function moveFile()
    {
        // if there is an error when moving the file, an exception will
        // be automatically thrown by move(). This will properly prevent
        // the entity from being persisted to the database on error
        $this->getFile()->move($this->getUploadRootDir(), $this->path);

        $this->setFile(null);
    }