mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 07:54:03 +00:00
Use only one config for queueing
This commit is contained in:
parent
74fbd816c2
commit
cc5611b24d
4 changed files with 28 additions and 27 deletions
|
|
@ -89,10 +89,9 @@ return [
|
||||||
// 'paypal_api_key' => 'services.paypal.api_key',
|
// 'paypal_api_key' => 'services.paypal.api_key',
|
||||||
],
|
],
|
||||||
'home_url' => '/app',
|
'home_url' => '/app',
|
||||||
'migrate_after_creation' => false, // run migrations after creating a tenant
|
|
||||||
'queue_automatic_migration' => false, // queue the automatic post-tenant-creation migrations
|
|
||||||
'delete_database_after_tenant_deletion' => false, // delete the tenant's database after deleting the tenant
|
|
||||||
'queue_database_creation' => false,
|
'queue_database_creation' => false,
|
||||||
|
'migrate_after_creation' => false, // run migrations after creating a tenant
|
||||||
'queue_database_deletion' => false,
|
'queue_database_deletion' => false,
|
||||||
|
'delete_database_after_tenant_deletion' => false, // delete the tenant's database after deleting the tenant
|
||||||
'unique_id_generator' => Stancl\Tenancy\UniqueIDGenerators\UUIDGenerator::class,
|
'unique_id_generator' => Stancl\Tenancy\UniqueIDGenerators\UUIDGenerator::class,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -126,14 +126,14 @@ class DatabaseManager
|
||||||
* Create a database for a tenant.
|
* Create a database for a tenant.
|
||||||
*
|
*
|
||||||
* @param Tenant $tenant
|
* @param Tenant $tenant
|
||||||
* @param ShouldQueue[]|callable[] $afterCreating
|
* @param \Illuminate\Contracts\Queue\ShouldQueue[]|callable[] $afterCreating
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createDatabase(Tenant $tenant, array $afterCreating = [])
|
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::withChain($afterCreating)->dispatch($manager, $database);
|
QueuedTenantDatabaseCreator::withChain($afterCreating)->dispatch($manager, $database);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -63,21 +63,19 @@ class TenantManager
|
||||||
|
|
||||||
$this->storage->createTenant($tenant);
|
$this->storage->createTenant($tenant);
|
||||||
|
|
||||||
|
/** @var \Illuminate\Contracts\Queue\ShouldQueue[]|callable[] $afterCreating */
|
||||||
$afterCreating = [];
|
$afterCreating = [];
|
||||||
|
|
||||||
if ($this->shouldMigrateAfterCreation()) {
|
if ($this->shouldMigrateAfterCreation()) {
|
||||||
if ($this->shouldQueueMigration()) {
|
$afterCreating += $this->databaseCreationQueued() ? [
|
||||||
$afterCreating = [
|
new QueuedTenantDatabaseMigrator($tenant),
|
||||||
new QueuedTenantDatabaseMigrator($tenant),
|
] : [
|
||||||
];
|
function () use ($tenant) {
|
||||||
} else {
|
$this->artisan->call('tenants:migrate', [
|
||||||
$afterCreating = [
|
'--tenants' => [$tenant['id']],
|
||||||
function () use ($tenant) {
|
]);
|
||||||
$this->artisan->call('tenants:migrate', [
|
},
|
||||||
'--tenants' => [$tenant['id']],
|
];
|
||||||
]);
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->database->createDatabase($tenant, $afterCreating);
|
$this->database->createDatabase($tenant, $afterCreating);
|
||||||
|
|
@ -323,9 +321,9 @@ class TenantManager
|
||||||
return $this->app['config']['tenancy.migrate_after_creation'] ?? false;
|
return $this->app['config']['tenancy.migrate_after_creation'] ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shouldQueueMigration(): bool
|
public function databaseCreationQueued(): bool
|
||||||
{
|
{
|
||||||
return $this->app['config']['tenancy.queue_automatic_migration'] ?? false;
|
return $this->app['config']['tenancy.queue_database_creation'] ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shouldDeleteDatabase(): bool
|
public function shouldDeleteDatabase(): bool
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Storage;
|
||||||
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
|
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
|
||||||
use Stancl\Tenancy\Exceptions\TenantDoesNotExistException;
|
use Stancl\Tenancy\Exceptions\TenantDoesNotExistException;
|
||||||
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
|
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
|
||||||
|
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
|
||||||
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
|
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
use Stancl\Tenancy\TenantManager;
|
use Stancl\Tenancy\TenantManager;
|
||||||
|
|
@ -249,23 +250,26 @@ class TenantManagerTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function automigration_can_be_queued()
|
public function automigration_is_be_queued()
|
||||||
{
|
{
|
||||||
Queue::fake();
|
Queue::fake();
|
||||||
|
|
||||||
config([
|
config([
|
||||||
|
'tenancy.queue_database_creation' => true,
|
||||||
'tenancy.migrate_after_creation' => true,
|
'tenancy.migrate_after_creation' => true,
|
||||||
'tenancy.queue_automatic_migration' => true,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$tenant = Tenant::new()->save();
|
$tenant = Tenant::new()->save();
|
||||||
tenancy()->initialize($tenant);
|
|
||||||
|
|
||||||
Queue::assertPushed(QueuedTenantDatabaseMigrator::class);
|
Queue::assertPushedWithChain(QueuedTenantDatabaseCreator::class, [
|
||||||
|
QueuedTenantDatabaseMigrator::class
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertFalse(\Schema::hasTable('users'));
|
// foreach (Queue::pushedJobs() as $job) {
|
||||||
(new QueuedTenantDatabaseMigrator($tenant))->handle();
|
// $job[0]['job']->handle(); // this doesn't execute the chained job
|
||||||
$this->assertTrue(\Schema::hasTable('users'));
|
// }
|
||||||
|
// tenancy()->initialize($tenant);
|
||||||
|
// $this->assertTrue(\Schema::hasTable('users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue