1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 12:24:04 +00:00

Use only one config for queueing

This commit is contained in:
Samuel Štancl 2019-10-17 13:38:09 +02:00
parent 74fbd816c2
commit cc5611b24d
4 changed files with 28 additions and 27 deletions

View file

@ -89,10 +89,9 @@ return [
// 'paypal_api_key' => 'services.paypal.api_key',
],
'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,
'migrate_after_creation' => false, // run migrations after creating a tenant
'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,
];

View file

@ -126,7 +126,7 @@ class DatabaseManager
* Create a database for a tenant.
*
* @param Tenant $tenant
* @param ShouldQueue[]|callable[] $afterCreating
* @param \Illuminate\Contracts\Queue\ShouldQueue[]|callable[] $afterCreating
* @return void
*/
public function createDatabase(Tenant $tenant, array $afterCreating = [])

View file

@ -63,14 +63,13 @@ class TenantManager
$this->storage->createTenant($tenant);
/** @var \Illuminate\Contracts\Queue\ShouldQueue[]|callable[] $afterCreating */
$afterCreating = [];
if ($this->shouldMigrateAfterCreation()) {
if ($this->shouldQueueMigration()) {
$afterCreating = [
$afterCreating += $this->databaseCreationQueued() ? [
new QueuedTenantDatabaseMigrator($tenant),
];
} else {
$afterCreating = [
] : [
function () use ($tenant) {
$this->artisan->call('tenants:migrate', [
'--tenants' => [$tenant['id']],
@ -78,7 +77,6 @@ class TenantManager
},
];
}
}
$this->database->createDatabase($tenant, $afterCreating);
@ -323,9 +321,9 @@ class TenantManager
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

View file

@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
use Stancl\Tenancy\Exceptions\TenantDoesNotExistException;
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\TenantManager;
@ -249,23 +250,26 @@ class TenantManagerTest extends TestCase
}
/** @test */
public function automigration_can_be_queued()
public function automigration_is_be_queued()
{
Queue::fake();
config([
'tenancy.queue_database_creation' => true,
'tenancy.migrate_after_creation' => true,
'tenancy.queue_automatic_migration' => true,
]);
$tenant = Tenant::new()->save();
tenancy()->initialize($tenant);
Queue::assertPushed(QueuedTenantDatabaseMigrator::class);
Queue::assertPushedWithChain(QueuedTenantDatabaseCreator::class, [
QueuedTenantDatabaseMigrator::class
]);
$this->assertFalse(\Schema::hasTable('users'));
(new QueuedTenantDatabaseMigrator($tenant))->handle();
$this->assertTrue(\Schema::hasTable('users'));
// foreach (Queue::pushedJobs() as $job) {
// $job[0]['job']->handle(); // this doesn't execute the chained job
// }
// tenancy()->initialize($tenant);
// $this->assertTrue(\Schema::hasTable('users'));
}
/** @test */