Skip to content

Commit

Permalink
Display messages during running migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek committed Jul 11, 2018
1 parent f16cc84 commit db5e206
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 40 deletions.
9 changes: 1 addition & 8 deletions Console/Migrations/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,11 @@ public function handle()
// Next, we will check to see if a path option has been defined. If it has
// we will use the path relative to the root of this installation folder
// so that migrations may be run for any path within the applications.
$this->migrator->run($this->getMigrationPaths(), [
$this->migrator->setOutput($this->output)->run($this->getMigrationPaths(), [
'pretend' => $this->option('pretend'),
'step' => $this->option('step'),
]);

// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having
// any instances of the OutputInterface contract passed into the class.
foreach ($this->migrator->getNotes() as $note) {
$this->output->writeln($note);
}

// Finally, if the "seed" option has been given, we will re-run the database
// seed task to re-populate the database, which is convenient when adding
// a migration and a seed at the same time, as it is only this command.
Expand Down
9 changes: 1 addition & 8 deletions Console/Migrations/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,9 @@ public function handle()
return $this->comment('Migration table not found.');
}

$this->migrator->reset(
$this->migrator->setOutput($this->output)->reset(
$this->getMigrationPaths(), $this->option('pretend')
);

// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having
// any instances of the OutputInterface contract passed into the class.
foreach ($this->migrator->getNotes() as $note) {
$this->output->writeln($note);
}
}

/**
Expand Down
9 changes: 1 addition & 8 deletions Console/Migrations/RollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,12 @@ public function handle()

$this->migrator->setConnection($this->option('database'));

$this->migrator->rollback(
$this->migrator->setOutput($this->output)->rollback(
$this->getMigrationPaths(), [
'pretend' => $this->option('pretend'),
'step' => (int) $this->option('step'),
]
);

// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having
// any instances of the OutputInterface contract passed into the class.
foreach ($this->migrator->getNotes() as $note) {
$this->output->writeln($note);
}
}

/**
Expand Down
37 changes: 21 additions & 16 deletions Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Database\Migrations;

use Illuminate\Console\OutputStyle;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -39,18 +40,18 @@ class Migrator
protected $connection;

/**
* The notes for the current operation.
* The paths to all of the migration files.
*
* @var array
*/
protected $notes = [];
protected $paths = [];

/**
* The paths to all of the migration files.
* The output interface implementation.
*
* @var array
* @var \Illuminate\Console\OutputStyle
*/
protected $paths = [];
protected $output;

/**
* Create a new migrator instance.
Expand All @@ -69,6 +70,20 @@ public function __construct(MigrationRepositoryInterface $repository,
$this->repository = $repository;
}

/**
* Set output.
*
* @param \Illuminate\Console\OutputStyle $output
*
* @return $this
*/
public function setOutput(OutputStyle $output)
{
$this->output = $output;

return $this;
}

/**
* Run the pending migrations at a given path.
*
Expand Down Expand Up @@ -573,16 +588,6 @@ public function getFilesystem()
*/
protected function note($message)
{
$this->notes[] = $message;
}

/**
* Get the notes for the last operation.
*
* @return array
*/
public function getNotes()
{
return $this->notes;
$this->output->writeln($message);
}
}

0 comments on commit db5e206

Please sign in to comment.