feat: introduce multi-tenancy by adding a structures table, structure_id to key models, and updating seeders for structure management.
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\Role;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SaaSTenantSeeder extends Seeder
|
||||
{
|
||||
@@ -28,7 +29,7 @@ class SaaSTenantSeeder extends Seeder
|
||||
DB::table('agents')->whereNull('structure_id')->update(['structure_id' => $cabm->id]);
|
||||
|
||||
// 3. Mettre à jour tous les services, templates, users, etc. vers cette structure
|
||||
$tables = ['services', 'integration_templates', 'integration_requests', 'users', 'service_tasks'];
|
||||
$tables = ['services', 'integration_templates', 'integration_requests', 'users', 'service_tasks', 'comments'];
|
||||
foreach ($tables as $table) {
|
||||
if (Schema::hasColumn($table, 'structure_id')) {
|
||||
DB::table($table)->whereNull('structure_id')->update(['structure_id' => $cabm->id]);
|
||||
@@ -41,6 +42,21 @@ class SaaSTenantSeeder extends Seeder
|
||||
['guard_name' => 'web', 'structure_id' => null]
|
||||
);
|
||||
|
||||
// 5. Créer l'utilisateur Admin par défaut s'il n'existe pas
|
||||
$admin = User::withoutGlobalScope('structure')->firstOrCreate(
|
||||
['email' => 'admin@admin.com'],
|
||||
[
|
||||
'name' => 'Super Admin',
|
||||
'password' => Hash::make('password'),
|
||||
'structure_id' => $cabm->id
|
||||
]
|
||||
);
|
||||
|
||||
// Lui assigner le rôle SuperAdmin
|
||||
if (!$admin->hasRole('SuperAdmin')) {
|
||||
$admin->assignRole($superAdminRole);
|
||||
}
|
||||
|
||||
$this->command->info('Migration vers le mode SaaS terminée. Structure par défaut : CABM.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user