Skip to content

[12.x] Improve db:seed command output formatting and add database connection name with -v option #56315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/Illuminate/Database/Console/Seeds/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Console\Prohibitable;
use Illuminate\Console\View\Components\TwoColumnDetail;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down Expand Up @@ -56,6 +57,8 @@ public function __construct(Resolver $resolver)
*/
public function handle()
{
$isVerbose = $this->output->isVerbose();

if ($this->isProhibited() ||
! $this->confirmToProceed()) {
return Command::FAILURE;
Expand All @@ -67,11 +70,31 @@ public function handle()

$this->resolver->setDefaultConnection($this->getDatabase());

Model::unguarded(function () {
$seeder = $this->getSeeder();
$seeder = $this->getSeeder();

$startTime = microtime(true);

$name = get_class($seeder);

with(new TwoColumnDetail($this->output))->render(
$isVerbose
? sprintf('%s <fg=blue>%s</>', $name, $this->resolver->getDefaultConnection())
: $name,
'<fg=yellow;options=bold>RUNNING</>'
);

$this->output?->writeln('');

Model::unguarded(fn () => $seeder->__invoke());

$runTime = number_format((microtime(true) - $startTime) * 1000);

$this->components->task(get_class($seeder), $seeder);
});
with(new TwoColumnDetail($this->output))->render(
$isVerbose
? sprintf('%s <fg=blue>%s</>', $name, $this->resolver->getDefaultConnection())
: $name,
"<fg=gray>$runTime ms</> <fg=green;options=bold>DONE</>"
);

$this->output?->writeln('');

Expand Down