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

55 lines
1.2 KiB
PHP
Raw Normal View History

<?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;
2016-08-05 02:35:37 +00:00
/**
* 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
{
2016-08-05 02:35:37 +00:00
/**
* The database migrations directory.
*/
2016-12-04 16:33:52 +00:00
private const MIGRATIONS = "database/";
2016-08-05 02:35:37 +00:00
/**
* A quick description of this command.
* @return string.
*/
2016-12-04 16:33:52 +00:00
public function brief(): string
{
return 'Run the database migrations';
}
2016-08-05 02:35:37 +00:00
/**
* Does the migrating.
*/
2016-12-04 16:33:52 +00:00
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) {
2016-07-30 13:48:09 +00:00
$this->getLogger()->writeln(strip_tags($note));
}
}
}