Lorsqu'un super-admin crée un établissement via l'interface, le système doit automatiquement créer la base tenant, exécuter les migrations, créer le premier utilisateur admin et envoyer l'invitation — le tout de manière asynchrone pour ne pas bloquer la réponse HTTP. Ce mécanisme rend chaque établissement opérationnel dès sa création sans intervention manuelle sur l'infrastructure.
28 lines
654 B
PHP
28 lines
654 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\SuperAdmin\Infrastructure\Provisioning;
|
|
|
|
use App\SuperAdmin\Application\Port\TenantProvisioner;
|
|
use Override;
|
|
|
|
/**
|
|
* Provisions a tenant by creating the database and running migrations.
|
|
*/
|
|
final readonly class DatabaseTenantProvisioner implements TenantProvisioner
|
|
{
|
|
public function __construct(
|
|
private TenantDatabaseCreator $databaseCreator,
|
|
private TenantMigrator $migrator,
|
|
) {
|
|
}
|
|
|
|
#[Override]
|
|
public function provision(string $databaseName): void
|
|
{
|
|
$this->databaseCreator->create($databaseName);
|
|
$this->migrator->migrate($databaseName);
|
|
}
|
|
}
|