-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from doesntmattr/feature/status-descriptions
Feature/status descriptions
- Loading branch information
Showing
4 changed files
with
119 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Helper\Table; | ||
|
||
/** | ||
* @author Matthew Fitzgerald <[email protected]> | ||
|
@@ -30,7 +31,12 @@ protected function configure() | |
$this | ||
->setName($this->getName()) | ||
->setDescription('View the status of a set of migrations.') | ||
->addOption('show-versions', null, InputOption::VALUE_NONE, 'This will display a list of all available migrations and their status') | ||
->addOption( | ||
'show-versions', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'This will display a list of all available migrations and their status' | ||
) | ||
->setHelp(<<<'EOT' | ||
The <info>%command.name%</info> command outputs the status of a set of migrations: | ||
|
@@ -98,27 +104,58 @@ public function execute(InputInterface $input, OutputInterface $output) | |
'Available Migrations' => $configMap['num_available_migrations'], | ||
'New Migrations' => $numNewMigrations > 0 ? '<question>'.$numNewMigrations.'</question>' : 0, | ||
); | ||
|
||
foreach ($info as $name => $value) { | ||
$this->writeInfoLine($output, $name, $value); | ||
} | ||
|
||
$showVersions = $input->getOption('show-versions') ? true : false; | ||
if ($showVersions === true) { | ||
if ($input->getOption('show-versions')) { | ||
if ($migrations = $configuration->getMigrations()) { | ||
$output->writeln("\n <info>==</info> Available Migration Versions\n"); | ||
$rows = array(); | ||
$migratedVersions = $configuration->getMigratedVersions(); | ||
|
||
foreach ($migrations as $version) { | ||
$isMigrated = in_array($version->getVersion(), $migratedVersions); | ||
$status = $isMigrated ? '<info>migrated</info>' : '<error>not migrated</error>'; | ||
$output->writeln(' <comment>>></comment> '.Configuration::formatVersion($version->getVersion()).' (<comment>'.$version->getVersion().'</comment>)'.str_repeat(' ', 30 - strlen($name)).$status); | ||
$status = '<error>not migrated</error>'; | ||
|
||
if ($isMigrated) { | ||
$ts = $configuration->getMigratedTimestamp( | ||
$version->getVersion() | ||
); | ||
|
||
$status = sprintf( | ||
'<info>%s</info>', | ||
date('Y-m-d H:i', $ts) | ||
); | ||
} | ||
|
||
$versionTxt = sprintf('<comment>%s</comment>', $version->getVersion()); | ||
$desc = $version->getMigration()->getDescription(); | ||
if (strlen($desc) > 80) { | ||
$desc = substr($desc, 0, 78).'...'; | ||
} | ||
|
||
$rows[] = array($versionTxt, $status, $desc); | ||
} | ||
|
||
$table = new Table($output); | ||
$table->setHeaders(array('Version', 'Date Migrated', 'Description')) | ||
->setRows($rows) | ||
->render(); | ||
} | ||
|
||
$executedUnavailableMigrations = $configuration->getUnavailableMigratedVersions(); | ||
if ($executedUnavailableMigrations) { | ||
$output->writeln("\n <info>==</info> Previously Executed Unavailable Migration Versions\n"); | ||
foreach ($executedUnavailableMigrations as $executedUnavailableMigration) { | ||
$output->writeln(' <comment>>></comment> '.Configuration::formatVersion($executedUnavailableMigration).' (<comment>'.$executedUnavailableMigration.'</comment>)'); | ||
$output->writeln( | ||
sprintf( | ||
' <comment>>></comment> %s (<comment>%s</comment>)', | ||
Configuration::formatVersion($executedUnavailableMigration), | ||
$executedUnavailableMigration | ||
) | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -141,6 +178,11 @@ protected function writeInfoLine(OutputInterface $output, $name, $value) | |
); | ||
} | ||
|
||
/** | ||
* getName. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters