mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:14:03 +00:00
wip
This commit is contained in:
parent
2f3924531d
commit
74fbd816c2
2 changed files with 20 additions and 8 deletions
|
|
@ -126,17 +126,21 @@ class DatabaseManager
|
||||||
* Create a database for a tenant.
|
* Create a database for a tenant.
|
||||||
*
|
*
|
||||||
* @param Tenant $tenant
|
* @param Tenant $tenant
|
||||||
|
* @param ShouldQueue[]|callable[] $afterCreating
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createDatabase(Tenant $tenant)
|
public function createDatabase(Tenant $tenant, array $afterCreating = [])
|
||||||
{
|
{
|
||||||
$database = $tenant->getDatabaseName();
|
$database = $tenant->getDatabaseName();
|
||||||
$manager = $this->getTenantDatabaseManager($tenant);
|
$manager = $this->getTenantDatabaseManager($tenant);
|
||||||
|
|
||||||
if ($this->app['config']['tenancy.queue_database_creation'] ?? false) {
|
if ($this->app['config']['tenancy.queue_database_creation'] ?? false) {
|
||||||
QueuedTenantDatabaseCreator::dispatch($manager, $database);
|
QueuedTenantDatabaseCreator::withChain($afterCreating)->dispatch($manager, $database);
|
||||||
} else {
|
} else {
|
||||||
$manager->createDatabase($database);
|
$manager->createDatabase($database);
|
||||||
|
foreach ($afterCreating as $callback) {
|
||||||
|
$callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,18 +62,26 @@ class TenantManager
|
||||||
$this->ensureTenantCanBeCreated($tenant);
|
$this->ensureTenantCanBeCreated($tenant);
|
||||||
|
|
||||||
$this->storage->createTenant($tenant);
|
$this->storage->createTenant($tenant);
|
||||||
$this->database->createDatabase($tenant);
|
|
||||||
|
|
||||||
|
$afterCreating = [];
|
||||||
if ($this->shouldMigrateAfterCreation()) {
|
if ($this->shouldMigrateAfterCreation()) {
|
||||||
if ($this->shouldQueueMigration()) {
|
if ($this->shouldQueueMigration()) {
|
||||||
QueuedTenantDatabaseMigrator::dispatch($tenant);
|
$afterCreating = [
|
||||||
|
new QueuedTenantDatabaseMigrator($tenant),
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
|
$afterCreating = [
|
||||||
|
function () use ($tenant) {
|
||||||
$this->artisan->call('tenants:migrate', [
|
$this->artisan->call('tenants:migrate', [
|
||||||
'--tenants' => [$tenant['id']],
|
'--tenants' => [$tenant['id']],
|
||||||
]);
|
]);
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->database->createDatabase($tenant, $afterCreating);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue