mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 20:34:03 +00:00
Queued post-creation automigration
This commit is contained in:
parent
40f8fa346e
commit
071cc6f950
4 changed files with 52 additions and 3 deletions
|
|
@ -15,7 +15,10 @@ class QueuedTenantDatabaseCreator implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/** @var TenantDatabaseManager */
|
||||||
protected $databaseManager;
|
protected $databaseManager;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
protected $databaseName;
|
protected $databaseName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@ class QueuedTenantDatabaseDeleter implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/** @var TenantDatabaseManager */
|
||||||
protected $databaseManager;
|
protected $databaseManager;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
protected $databaseName;
|
protected $databaseName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
38
src/Jobs/QueuedTenantDatabaseMigrator.php
Normal file
38
src/Jobs/QueuedTenantDatabaseMigrator.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
|
class QueuedTenantDatabaseMigrator implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/** @var Tenant */
|
||||||
|
protected $tenant;
|
||||||
|
|
||||||
|
public function __construct(Tenant $tenant)
|
||||||
|
{
|
||||||
|
$this->tenant = $tenant;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
Artisan::call('tenants:migrate', [
|
||||||
|
'--tenants' => [$this->tenant->id],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
|
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
|
||||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
|
||||||
|
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal Class is subject to breaking changes in minor and patch versions.
|
* @internal Class is subject to breaking changes in minor and patch versions.
|
||||||
|
|
@ -64,9 +65,13 @@ class TenantManager
|
||||||
$this->database->createDatabase($tenant);
|
$this->database->createDatabase($tenant);
|
||||||
|
|
||||||
if ($this->shouldMigrateAfterCreation()) {
|
if ($this->shouldMigrateAfterCreation()) {
|
||||||
$this->artisan->call('tenants:migrate', [
|
if ($this->shouldQueueMigration()) {
|
||||||
'--tenants' => [$tenant['id']],
|
QueuedTenantDatabaseMigrator::dispatch($tenant);
|
||||||
]);
|
} else {
|
||||||
|
$this->artisan->call('tenants:migrate', [
|
||||||
|
'--tenants' => [$tenant['id']],
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue