2016-07-30 13:48:09 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Holds the migration status command controller.
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura\Console\Command;
|
|
|
|
|
|
|
|
use CLIFramework\Command;
|
|
|
|
use CLIFramework\Component\Table\Table;
|
|
|
|
use Illuminate\Database\Migrations\Migrator;
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
use Sakura\DB;
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the status of the database migrations.
|
|
|
|
* @package Sakura
|
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
|
|
|
*/
|
2016-07-30 13:48:09 +00:00
|
|
|
class DatabaseStatusCommand extends Command
|
|
|
|
{
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* The database migrations directory.
|
|
|
|
*/
|
2016-07-30 13:48:09 +00:00
|
|
|
const MIGRATIONS = "database/";
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* A quick description of this command.
|
|
|
|
* @return string.
|
|
|
|
*/
|
2016-07-30 13:48:09 +00:00
|
|
|
public function brief()
|
|
|
|
{
|
|
|
|
return 'Show the status of each migration';
|
|
|
|
}
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Fulfills the purpose of what is described above this class.
|
|
|
|
*/
|
2016-07-30 13:48:09 +00:00
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
$repository = DB::getMigrationRepository();
|
|
|
|
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
|
|
|
|
|
|
|
|
if (!$migrator->repositoryExists()) {
|
|
|
|
$this->getLogger()->writeln("No migrations found!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ran = $repository->getRan();
|
|
|
|
|
|
|
|
$migrations = new Table;
|
|
|
|
|
|
|
|
$migrations->setHeaders([
|
|
|
|
'Ran?',
|
|
|
|
'Migration',
|
|
|
|
]);
|
|
|
|
|
|
|
|
foreach ($migrator->getMigrationFiles(ROOT . self::MIGRATIONS) as $migration) {
|
|
|
|
$migrations->addRow([in_array($migration, $ran) ? 'Y' : 'N', $migration]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->getLogger()->write($migrations->render());
|
|
|
|
}
|
|
|
|
}
|