Skip to content

Commit

Permalink
Added support in DB::prohibitDestructiveCommands to prohibit Rollback…
Browse files Browse the repository at this point in the history
…Command

Signed-off-by: Rainer Bendig <hexathos@gmail.com>
  • Loading branch information
hexathos committed Jan 17, 2025
1 parent aa01ced commit 38d9107
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace Illuminate\Database\Console\Migrations;

use Illuminate\Console\ConfirmableTrait;
use Illuminate\Console\Prohibitable;
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

#[AsCommand('migrate:rollback')]
class RollbackCommand extends BaseCommand
{
use ConfirmableTrait;
use ConfirmableTrait, Prohibitable;

/**
* The console command name.
Expand Down Expand Up @@ -53,8 +54,9 @@ public function __construct(Migrator $migrator)
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return 1;
if ($this->isProhibited() ||
! $this->confirmToProceed()) {
return Command::FAILURE;

Check failure on line 59 in src/Illuminate/Database/Console/Migrations/RollbackCommand.php

View workflow job for this annotation

GitHub Actions / Source Code

Access to constant FAILURE on an unknown class Illuminate\Database\Console\Migrations\Command.
}

$this->migrator->usingConnection($this->option('database'), function () {
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Support/Facades/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Console\Migrations\FreshCommand;
use Illuminate\Database\Console\Migrations\RefreshCommand;
use Illuminate\Database\Console\Migrations\ResetCommand;
use Illuminate\Database\Console\Migrations\RollbackCommand;
use Illuminate\Database\Console\WipeCommand;

/**
Expand Down Expand Up @@ -132,6 +133,7 @@ public static function prohibitDestructiveCommands(bool $prohibit = true)
FreshCommand::prohibit($prohibit);
RefreshCommand::prohibit($prohibit);
ResetCommand::prohibit($prohibit);
RollbackCommand::prohibit($prohibit);
WipeCommand::prohibit($prohibit);
}

Expand Down

0 comments on commit 38d9107

Please sign in to comment.