Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make db:seed command prohibitable #55238

Merged
merged 1 commit into from
Apr 1, 2025

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