feat: add canopy/leopard/curagreen users and block migrate:fresh

- 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
This commit is contained in:
kelly
2025-12-06 21:50:26 -07:00
parent aadd7a500a
commit 109d9cd39d
2 changed files with 70 additions and 5 deletions

View File

@@ -0,0 +1,43 @@
<?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();
}
}

View File

@@ -70,6 +70,24 @@ class ProductionSyncSeeder extends Seeder
'last_name' => 'Owner',
'user_type' => 'seller',
],
[
'email' => 'canopy@example.com',
'first_name' => 'Canopy',
'last_name' => 'AZ',
'user_type' => 'seller',
],
[
'email' => 'leopardaz@example.com',
'first_name' => 'Leopard',
'last_name' => 'AZ',
'user_type' => 'seller',
],
[
'email' => 'curagreen@example.com',
'first_name' => 'Curagreen',
'last_name' => 'LLC',
'user_type' => 'seller',
],
[
'email' => 'brand-manager@example.com',
'first_name' => 'Brand',
@@ -96,7 +114,9 @@ class ProductionSyncSeeder extends Seeder
// Get user IDs
$cannabrandsOwner = User::where('email', 'cannabrands-owner@example.com')->first();
$seller = User::where('email', 'seller@example.com')->first();
$canopyOwner = User::where('email', 'canopy@example.com')->first();
$leopardOwner = User::where('email', 'leopardaz@example.com')->first();
$curagreenOwner = User::where('email', 'curagreen@example.com')->first();
$buyer = User::where('email', 'buyer@example.com')->first();
$pendingBuyer = User::where('email', 'pending-buyer@example.com')->first();
@@ -113,7 +133,7 @@ class ProductionSyncSeeder extends Seeder
'name' => 'Canopy AZ LLC',
'slug' => 'canopy',
'type' => 'seller',
'owner_user_id' => $seller?->id,
'owner_user_id' => $canopyOwner?->id,
'is_active' => true,
'status' => 'approved',
],
@@ -121,7 +141,7 @@ class ProductionSyncSeeder extends Seeder
'name' => 'Curagreen LLC',
'slug' => 'curagreen',
'type' => 'seller',
'owner_user_id' => $seller?->id,
'owner_user_id' => $curagreenOwner?->id,
'is_active' => true,
'status' => 'approved',
],
@@ -129,7 +149,7 @@ class ProductionSyncSeeder extends Seeder
'name' => 'Leopard AZ LLC',
'slug' => 'leopard-az',
'type' => 'seller',
'owner_user_id' => $seller?->id,
'owner_user_id' => $leopardOwner?->id,
'is_active' => true,
'status' => 'approved',
],
@@ -161,7 +181,9 @@ class ProductionSyncSeeder extends Seeder
// Attach users to their businesses
$this->attachUserToBusinesses($cannabrandsOwner, ['cannabrands']);
$this->attachUserToBusinesses($seller, ['canopy', 'curagreen', 'leopard-az']);
$this->attachUserToBusinesses($canopyOwner, ['canopy']);
$this->attachUserToBusinesses($leopardOwner, ['leopard-az']);
$this->attachUserToBusinesses($curagreenOwner, ['curagreen']);
$this->attachUserToBusinesses($buyer, ['greenleaf-dispensary']);
$this->attachUserToBusinesses($pendingBuyer, ['phoenix-cannabis-collective']);
}