1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-06-21 00:14:04 +00:00

expand includeInPending logic

This commit is contained in:
Samuel Stancl 2026-06-05 15:09:50 -07:00
parent 5ab14fdd5c
commit b7bd439a9d
No known key found for this signature in database
GPG key ID: BA146259A1E16C57
3 changed files with 18 additions and 8 deletions

View file

@ -20,8 +20,12 @@ class MigrateDatabase implements ShouldQueue
/**
* Should pending tenants be included while migrating,
* regardless of the tenancy.pending.include_in_queries config value.
*
* If false, pending tenants will be specifically excluded.
*
* If null, default to tenancy.pending.include_in_queries config.
*/
public static bool $includePending = true;
public static ?bool $includePending = true;
public function __construct(
protected TenantWithDatabase&Model $tenant,
@ -31,7 +35,7 @@ class MigrateDatabase implements ShouldQueue
{
Artisan::call('tenants:migrate', [
'--tenants' => [$this->tenant->getTenantKey()],
'--with-pending' => static::$includePending,
'--with-pending' => static::$includePending ?? config('tenancy.pending.include_in_queries'),
]);
}
}

View file

@ -20,8 +20,12 @@ class SeedDatabase implements ShouldQueue
/**
* Should pending tenants be included while seeding,
* regardless of the tenancy.pending.include_in_queries config value.
*
* If false, pending tenants will be specifically excluded.
*
* If null, default to tenancy.pending.include_in_queries config.
*/
public static bool $includePending = true;
public static ?bool $includePending = true;
public function __construct(
protected TenantWithDatabase&Model $tenant,
@ -31,7 +35,7 @@ class SeedDatabase implements ShouldQueue
{
Artisan::call('tenants:seed', [
'--tenants' => [$this->tenant->getTenantKey()],
'--with-pending' => static::$includePending,
'--with-pending' => static::$includePending ?? config('tenancy.pending.include_in_queries'),
]);
}
}

View file

@ -268,7 +268,7 @@ test('pending tenants can have default attributes for non-nullable columns', fun
expect($fn)->toThrow(QueryException::class);
})->with([true, false]);
test('pending tenant databases can be migrated using a job unless configured otherwise', function (bool $includeInQueries, bool $migrateWithPending) {
test('pending tenant databases can be migrated using a job unless configured otherwise', function (bool $includeInQueries, ?bool $migrateWithPending) {
config([
'tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class],
'tenancy.pending.include_in_queries' => $includeInQueries,
@ -293,16 +293,17 @@ test('pending tenant databases can be migrated using a job unless configured oth
// MigrateDatabase includes/excludes pending tenants based on its $includePending property,
// regardless of the tenancy.pending.include_in_queries config.
expect(Schema::hasTable('users'))->toBe($migrateWithPending);
expect(Schema::hasTable('users'))->toBe($migrateWithPending ?? $includeInQueries);
})->with([
'include pending in queries' => [true],
'exclude pending from queries' => [false],
])->with([
'migrate with pending' => [true],
'migrate without pending' => [false],
'default to config' => [null],
]);
test('pending tenant databases can be seeded using a job unless configured otherwise', function ($includeInQueries, $seedWithPending) {
test('pending tenant databases can be seeded using a job unless configured otherwise', function (bool $includeInQueries, ?bool $seedWithPending) {
config([
'tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class],
'tenancy.pending.include_in_queries' => $includeInQueries,
@ -328,13 +329,14 @@ test('pending tenant databases can be seeded using a job unless configured other
// SeedDatabase includes/excludes pending tenants based on its $includePending property,
// regardless of the tenancy.pending.include_in_queries config.
expect(User::where('email', 'seeded@user')->exists())->toBe($seedWithPending);
expect(User::where('email', 'seeded@user')->exists())->toBe($seedWithPending ?? $includeInQueries);
})->with([
'include pending in queries' => [true],
'exclude pending from queries' => [false],
])->with([
'seed with pending' => [true],
'seed without pending' => [false],
'default to config' => [null],
]);
test('jobs that run before tenants get fully created recognize pending tenants', function () {