Skip to content
Draft
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
29 changes: 28 additions & 1 deletion src/Illuminate/Database/Console/Migrations/RollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public function __construct(Migrator $migrator)
}

/**
* Execute the console command.
* Handle the execution of the rollback command.
*
* Displays the list of migrations that will be rolled back and asks
* for user confirmation before proceeding, unless the --force option
* is provided. Supports --step, --batch, and --pretend options.
*
* @return int
*/
Expand All @@ -60,6 +64,29 @@ public function handle()
}

$this->migrator->usingConnection($this->option('database'), function () {
$migrations = $this->migrator->getRepository()->getLast();

if ($this->option('step')) {
$migrations = $this->migrator->getRepository()->getMigrations($this->option('step'));
}

if (empty($migrations)) {
$this->info('Nothing to rollback.');
return;
}

$this->line('Migrations to be rolled back:');
foreach ($migrations as $migration) {
$this->line(' - '.$migration->migration);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, you could use Symfony's listing() method here:

Suggested change
$this->line('Migrations to be rolled back:');
$this->output->listing($migrations->map(fn ($migration) $migration->migration));

if (! $this->option('force')) {
if (! $this->confirm('Do you really want to rollback these migrations?')) {
$this->info('Rollback cancelled.');
return;
}
}

$this->migrator->setOutput($this->output)->rollback(
$this->getMigrationPaths(), [
'pretend' => $this->option('pretend'),
Expand Down
Loading