From 68d6592f2d52f76d3552a06d16221961b9745291 Mon Sep 17 00:00:00 2001 From: Akash <75482117+mdrakash@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:52:06 +0600 Subject: [PATCH] Show rollback migration list before confirmation What to Implement: - Determine which migrations will be rolled back - Display their names before execution - Ask for confirmation - Skip confirmation if --force is provided - Keep production safeguards intact --- .../Console/Migrations/RollbackCommand.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Console/Migrations/RollbackCommand.php b/src/Illuminate/Database/Console/Migrations/RollbackCommand.php index 9c3543ec5bfe..158b008fa10e 100755 --- a/src/Illuminate/Database/Console/Migrations/RollbackCommand.php +++ b/src/Illuminate/Database/Console/Migrations/RollbackCommand.php @@ -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 */ @@ -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); + } + + 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'),