feat: block destructive DB commands in production
Listen for CommandStarting event and throw RuntimeException for migrate:fresh, migrate:refresh, migrate:reset, db:wipe, db:seed when APP_ENV=production. Prevents accidental data loss even with --force. Also removes old non-functional closure-based override in routes/console.php.
This commit is contained in:
@@ -27,7 +27,14 @@ class EventServiceProvider extends AbstractEventServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
if (app()->environment('production')) {
|
||||
Event::listen(\Illuminate\Console\Events\CommandStarting::class, function ($event) {
|
||||
$blocked = ['migrate:fresh', 'migrate:refresh', 'migrate:reset', 'db:wipe', 'db:seed'];
|
||||
if (in_array($event->command, $blocked)) {
|
||||
throw new \RuntimeException("BLOCKED: {$event->command} is disabled in production.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
/*
|
||||
@@ -18,9 +17,3 @@ use Illuminate\Support\Facades\Artisan;
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote');
|
||||
|
||||
if ('production' === App::environment()) {
|
||||
Artisan::command('migrate:fresh', function () {
|
||||
$this->comment('You are not allowed to do this in production.');
|
||||
})->describe('Override default command in production.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user