This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/Console/Command/DatabaseMigrateCommand.php
2016-12-11 15:49:32 +01:00

54 lines
1.3 KiB
PHP

<?php
/**
* Holds the migration command controller.
* @package Sakura
*/
namespace Sakura\Console\Command;
use CLIFramework\Command;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Filesystem\Filesystem;
use Sakura\DB;
/**
* Brings the database up to speed with the ones in the database folder.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class DatabaseMigrateCommand extends Command
{
/**
* The database migrations directory.
*/
private const MIGRATIONS = "database/";
/**
* A quick description of this command.
* @return string.
*/
public function brief(): string
{
return 'Run the database migrations.';
}
/**
* Does the migrating.
*/
public function execute(): void
{
$repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
if (!$migrator->repositoryExists()) {
$this->getLogger()->writeln("Run 'database-install' first!");
return;
}
$migrator->run(path(self::MIGRATIONS));
foreach ($migrator->getNotes() as $note) {
$this->getLogger()->writeln(strip_tags($note));
}
}
}