1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 12:24:04 +00:00
This commit is contained in:
Samuel Štancl 2019-10-16 08:56:33 +02:00
parent 2f3924531d
commit 74fbd816c2
2 changed files with 20 additions and 8 deletions

View file

@ -126,17 +126,21 @@ class DatabaseManager
* Create a database for a tenant.
*
* @param Tenant $tenant
* @param ShouldQueue[]|callable[] $afterCreating
* @return void
*/
public function createDatabase(Tenant $tenant)
public function createDatabase(Tenant $tenant, array $afterCreating = [])
{
$database = $tenant->getDatabaseName();
$manager = $this->getTenantDatabaseManager($tenant);
if ($this->app['config']['tenancy.queue_database_creation'] ?? false) {
QueuedTenantDatabaseCreator::dispatch($manager, $database);
QueuedTenantDatabaseCreator::withChain($afterCreating)->dispatch($manager, $database);
} else {
$manager->createDatabase($database);
foreach ($afterCreating as $callback) {
$callback();
}
}
}

View file

@ -62,18 +62,26 @@ class TenantManager
$this->ensureTenantCanBeCreated($tenant);
$this->storage->createTenant($tenant);
$this->database->createDatabase($tenant);
$afterCreating = [];
if ($this->shouldMigrateAfterCreation()) {
if ($this->shouldQueueMigration()) {
QueuedTenantDatabaseMigrator::dispatch($tenant);
$afterCreating = [
new QueuedTenantDatabaseMigrator($tenant),
];
} else {
$afterCreating = [
function () use ($tenant) {
$this->artisan->call('tenants:migrate', [
'--tenants' => [$tenant['id']],
]);
},
];
}
}
$this->database->createDatabase($tenant, $afterCreating);
return $this;
}