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/DatabaseStatusCommand.php

65 lines
1.5 KiB
PHP
Raw Permalink Normal View History

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-12-04 16:33:52 +00:00
private const MIGRATIONS = "database/";
2016-07-30 13:48:09 +00:00
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
2016-07-30 13:48:09 +00:00
{
2016-12-11 14:49:32 +00:00
return 'Show the status of each migration.';
2016-07-30 13:48:09 +00:00
}
2016-08-05 02:35:37 +00:00
/**
* Fulfills the purpose of what is described above this class.
*/
2016-12-04 16:33:52 +00:00
public function execute(): void
2016-07-30 13:48:09 +00:00
{
$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(path(self::MIGRATIONS)) as $migration) {
2016-07-30 13:48:09 +00:00
$migrations->addRow([in_array($migration, $ran) ? 'Y' : 'N', $migration]);
}
$this->getLogger()->write($migrations->render());
}
}