mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:34:03 +00:00
add $ignoreExisting static property to CreateDatabase
This commit is contained in:
parent
fdd401fc8f
commit
bf1ba69fe3
1 changed files with 14 additions and 3 deletions
|
|
@ -12,6 +12,8 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
use Stancl\Tenancy\Database\DatabaseManager;
|
use Stancl\Tenancy\Database\DatabaseManager;
|
||||||
|
use Stancl\Tenancy\Database\Exceptions\TenantDatabaseAlreadyExistsException;
|
||||||
|
use Stancl\Tenancy\Database\Exceptions\TenantDatabaseUserAlreadyExistsException;
|
||||||
use Stancl\Tenancy\Events\CreatingDatabase;
|
use Stancl\Tenancy\Events\CreatingDatabase;
|
||||||
use Stancl\Tenancy\Events\DatabaseCreated;
|
use Stancl\Tenancy\Events\DatabaseCreated;
|
||||||
|
|
||||||
|
|
@ -19,6 +21,8 @@ class CreateDatabase implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public static bool $ignoreExisting = false;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected TenantWithDatabase&Model $tenant,
|
protected TenantWithDatabase&Model $tenant,
|
||||||
) {
|
) {
|
||||||
|
|
@ -34,10 +38,17 @@ class CreateDatabase implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->tenant->database()->makeCredentials();
|
$this->tenant->database()->makeCredentials();
|
||||||
|
|
||||||
|
try {
|
||||||
$databaseManager->ensureTenantCanBeCreated($this->tenant);
|
$databaseManager->ensureTenantCanBeCreated($this->tenant);
|
||||||
$this->tenant->database()->manager()->createDatabase($this->tenant);
|
$this->tenant->database()->manager()->createDatabase($this->tenant);
|
||||||
|
|
||||||
event(new DatabaseCreated($this->tenant));
|
event(new DatabaseCreated($this->tenant));
|
||||||
|
} catch (TenantDatabaseAlreadyExistsException | TenantDatabaseUserAlreadyExistsException $e) {
|
||||||
|
if (! static::$ignoreExisting) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue