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.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user