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

[2.x] Allow automatic seeding after automatic migrations (#160)

This commit is contained in:
Chris Brown 2019-10-17 13:25:30 -04:00 committed by Samuel Štancl
parent 3dbbbe8b24
commit d5b01219fd
4 changed files with 113 additions and 6 deletions

View file

@ -10,6 +10,7 @@ use Illuminate\Support\Collection;
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseSeeder;
/**
* @internal Class is subject to breaking changes in minor and patch versions.
@ -67,15 +68,23 @@ class TenantManager
$afterCreating = [];
if ($this->shouldMigrateAfterCreation()) {
$afterCreating += $this->databaseCreationQueued() ? [
new QueuedTenantDatabaseMigrator($tenant),
] : [
function () use ($tenant) {
$afterCreating[] = $this->databaseCreationQueued()
? new QueuedTenantDatabaseMigrator($tenant)
: function () use ($tenant) {
$this->artisan->call('tenants:migrate', [
'--tenants' => [$tenant['id']],
]);
},
];
};
}
if ($this->shouldSeedAfterMigration()) {
$afterCreating[] = $this->databaseCreationQueued()
? new QueuedTenantDatabaseSeeder($tenant, $this->getSeederParameters())
: function () use ($tenant) {
$this->artisan->call('tenants:seed', [
'--tenants' => [$tenant['id']],
] + $this->getSeederParameters());
};
}
$this->database->createDatabase($tenant, $afterCreating);
@ -321,6 +330,11 @@ class TenantManager
return $this->app['config']['tenancy.migrate_after_creation'] ?? false;
}
public function shouldSeedAfterMigration(): bool
{
return $this->shouldMigrateAfterCreation() && $this->app['config']['tenancy.seed_after_migration'] ?? false;
}
public function databaseCreationQueued(): bool
{
return $this->app['config']['tenancy.queue_database_creation'] ?? false;
@ -331,6 +345,11 @@ class TenantManager
return $this->app['config']['tenancy.delete_database_after_tenant_deletion'] ?? false;
}
public function getSeederParameters()
{
return $this->app['config']['tenancy.seeder_parameters'] ?? [];
}
/**
* Add an event listener.
*