- Add canopy@example.com, leopardaz@example.com, curagreen@example.com users - Each seller business now has its own dedicated owner user - SafeFreshCommand blocks migrate:fresh except for test databases - Prevents accidental data loss in local, dev, staging, and production
44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Database\Console\Migrations\FreshCommand;
|
|
|
|
/**
|
|
* Override migrate:fresh to prevent accidental data loss.
|
|
*
|
|
* This command blocks migrate:fresh in all environments except when
|
|
* explicitly targeting a test database (DB_DATABASE=testing or *_test_*).
|
|
*/
|
|
class SafeFreshCommand extends FreshCommand
|
|
{
|
|
public function handle()
|
|
{
|
|
// Check both config and direct env (env var may not be in config yet)
|
|
$database = env('DB_DATABASE', config('database.connections.pgsql.database'));
|
|
|
|
// Allow migrate:fresh ONLY for test databases
|
|
$isTestDatabase = $database === 'testing'
|
|
|| str_contains($database, '_test_')
|
|
|| str_contains($database, 'testing_');
|
|
|
|
if (! $isTestDatabase) {
|
|
$this->components->error('migrate:fresh is BLOCKED to prevent data loss!');
|
|
$this->components->warn("Database: {$database}");
|
|
$this->newLine();
|
|
$this->components->bulletList([
|
|
'This command drops ALL tables and destroys ALL data.',
|
|
'It is blocked in local, dev, staging, and production.',
|
|
'For testing: DB_DATABASE=testing ./vendor/bin/sail artisan migrate:fresh',
|
|
'To seed existing data: php artisan db:seed --class=ProductionSyncSeeder',
|
|
]);
|
|
|
|
return 1;
|
|
}
|
|
|
|
$this->components->info("Running migrate:fresh on TEST database: {$database}");
|
|
|
|
return parent::handle();
|
|
}
|
|
}
|