1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 16:14:02 +00:00

[2.x] Queued post-creation automigration (#154)

* Queued post-creation automigration

* Add shouldQueueMigration()

* Automigration test, config key, QueueTenancyBootstrapper support for QueueFake

* Apply fixes from StyleCI

* Fix if statement
This commit is contained in:
Samuel Štancl 2019-10-04 21:34:17 +02:00 committed by GitHub
parent b66574b1ab
commit abd0b8f04e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 6 deletions

View file

@ -9,6 +9,7 @@ use Illuminate\Foundation\Application;
use Illuminate\Support\Collection;
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
/**
* @internal Class is subject to breaking changes in minor and patch versions.
@ -64,9 +65,13 @@ class TenantManager
$this->database->createDatabase($tenant);
if ($this->shouldMigrateAfterCreation()) {
$this->artisan->call('tenants:migrate', [
'--tenants' => [$tenant['id']],
]);
if ($this->shouldQueueMigration()) {
QueuedTenantDatabaseMigrator::dispatch($tenant);
} else {
$this->artisan->call('tenants:migrate', [
'--tenants' => [$tenant['id']],
]);
}
}
return $this;
@ -306,6 +311,11 @@ class TenantManager
return $this->app['config']['tenancy.migrate_after_creation'] ?? false;
}
public function shouldQueueMigration(): bool
{
return $this->app['config']['tenancy.queue_automatic_migration'] ?? false;
}
public function shouldDeleteDatabase(): bool
{
return $this->app['config']['tenancy.delete_database_after_tenant_deletion'] ?? false;