Skip to content

Commit

Permalink
Add the batch number to migrate:status command
Browse files Browse the repository at this point in the history
  • Loading branch information
moElwan committed Sep 25, 2017
1 parent 7619e4f commit c5d0277
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Illuminate/Database/Console/Migrations/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public function handle()
}

$ran = $this->migrator->getRepository()->getRan();
$migrationsBatches = $this->migrator->getRepository()->getMigrationsBatches();

if (count($migrations = $this->getStatusFor($ran)) > 0) {
$this->table(['Ran?', 'Migration'], $migrations);
if (count($migrations = $this->getStatusFor($ran, $migrationsBatches)) > 0) {
$this->table(['Ran?', 'Migration', 'Batch'], $migrations);
} else {
$this->error('No migrations found');
}
Expand All @@ -68,16 +69,17 @@ public function handle()
* Get the status for the given ran migrations.
*
* @param array $ran
* @param array $migrationsBatches
* @return \Illuminate\Support\Collection
*/
protected function getStatusFor(array $ran)
protected function getStatusFor(array $ran, array $migrationsBatches)
{
return Collection::make($this->getAllMigrationFiles())
->map(function ($migration) use ($ran) {
->map(function ($migration) use ($ran, $migrationsBatches) {
$migrationName = $this->migrator->getMigrationName($migration);

return in_array($migrationName, $ran)
? ['<info>Y</info>', $migrationName]
? ['<info>Y</info>', $migrationName, $migrationsBatches[$migrationName]]
: ['<fg=red>N</fg=red>', $migrationName];
});
}
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public function getRan()
->pluck('migration')->all();
}

/**
* Get the ran migrations with batch numbers.
*
* @return array
*/
public function getMigrationsBatches()
{
return $this->table()
->orderBy('batch', 'asc')
->orderBy('migration', 'asc')
->pluck('batch', 'migration')->all();
}

/**
* Get list of migrations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ interface MigrationRepositoryInterface
*/
public function getRan();

/**
* Get the ran migrations with batch numbers for a given package.
*
* @return array
*/
public function getMigrationsBatches();

/**
* Get list of migrations.
*
Expand Down

0 comments on commit c5d0277

Please sign in to comment.