Skip to content

Conversation

@spawnia
Copy link
Contributor

@spawnia spawnia commented Apr 1, 2025

I think it is generally undesirable and potentially unsafe to execute seeders in production databases. This change allows users fine-grained control to prohibit db:seed from running.

This is a follow-up from #55231, but only adds the Prohibitable trait without changing DB::prohibitDestructiveCommands.

Now, I have to do something like this:

// DBServiceProvider.php
DB::prohibitDestructiveCommands();
$this->app->extend(SeedCommand::class, fn (): ProhibitableSeedCommand => new ProhibitableSeedCommand($this->app->make(ConnectionResolverInterface::class)));
ProhibitableSeedCommand::prohibit();

// ProhibitableSeedCommand.php
use Illuminate\Console\Prohibitable;
use Illuminate\Database\Console\Seeds\SeedCommand;

final class ProhibitableSeedCommand extends SeedCommand
{
    use Prohibitable;

    public function handle(): int
    {
        if ($this->isProhibited()) {
            return self::FAILURE;
        }

        return parent::handle();
    }
}

With this pull request, this simply becomes this, without the need for any class overrides:

DB::prohibitDestructiveCommands();
SeedCommand::prohibit();

I think it is generally undesirable and potentially unsafe to execute seeders in production databases.
This change allows users fine-grained control to prohibit `db:seed` from running.
@taylorotwell taylorotwell merged commit c74e7e3 into laravel:12.x Apr 1, 2025
40 of 41 checks passed
@spawnia spawnia deleted the db-seed-prohibitable branch April 2, 2025 07:09
@andrey-helldar
Copy link
Contributor

I'll just leave it here: https://deploy-operations.dragon-code.pro 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants