Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthewyeend/prevent-destructive-commands
A Laravel package to stop destructive commands
https://github.com/matthewyeend/prevent-destructive-commands
commands composer composer-package laravel laravel-11 laravel-package package
Last synced: 3 days ago
JSON representation
A Laravel package to stop destructive commands
- Host: GitHub
- URL: https://github.com/matthewyeend/prevent-destructive-commands
- Owner: MatthewYeend
- License: mit
- Created: 2025-01-09T19:05:12.000Z (15 days ago)
- Default Branch: main
- Last Pushed: 2025-01-21T16:26:11.000Z (3 days ago)
- Last Synced: 2025-01-21T17:43:38.246Z (3 days ago)
- Topics: commands, composer, composer-package, laravel, laravel-11, laravel-package, package
- Language: PHP
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Prevent Destructive Commands
Prevent Destructive Commands is a Laravel package that disables certain destructive Artisan commands in production environments to protect your database and application data.
---
## Features
This package disables the following commands when the application is in the production environment:- `php artisan migrate:fresh` - Drops all tables and re-runs migrations.
- `php artisan migrate:reset` - Rolls back all migrations.
- `php artisan migrate:rollback` - Rolls back a batch of migrations.
- `php artisan db:wipe` - Drops all databases.
In non-production environments, these commands will function as usual.---
## Installation
1. Install via Composer:
`composer require MattYeend/prevent-destructive-commands`---
## Compatibility
This package is compatible with Laravel 9, 10, and 11.
---
## Registration
### Laravel 9 and 10
For Laravel 9 and 10, the service provider is automatically registered via Laravel's package discovery. No additional steps are required.### Laravel 11
Laravel 11 introduces stricter service provider registration. You need to manually register the service provider in the `config/app.php` file:
1. Open the `config/app.php` file.
2. Add the service provider to the providers array:
```bash
'providers' => [
// Other Service Providers...MattYeend\PreventDestructiveCommands\PreventDestructiveCommandsServiceProvider::class,
],
```---
## Usage
The package automatically disables destructive commands in the production environment. No additional setup is required.
---
### Running a Disabled Command in Production
If you attempt to run any of the disabled commands in a production environment, you’ll receive an error message like:
`This 'migrate:fresh' command is disabled in this environment for safety.`
In non-production environments (e.g., `local`, `staging`), the commands will execute normally.---
### Environment Configuration
Ensure your `.env` file correctly specifies the application environment:
`APP_ENV=production`
The package determines the current environment using Laravel’s `app()->environment()` method.#### Testing
You can simulate the package behavior by temporarily setting your application environment to `production`. To do this:
1. Edit `.env`
```dotenv
APP_ENV=production
```
2. Attempt to run a destructive command, e.g.:
```bash
php artisan migrate:fresh
```
3. You should see an error message similar to the following:
```kotlin
This 'migrate:fresh' command is disabled in this environment for safety.
```##### Testing through package
1. Install dependencies
```bash
composer install
```
2. Run the test
```bash
composer test
```---
## License
This package is licensed under the MIT License.---
## Contributing
Feel free to fork the repository and submit pull requests for improvements or new features!