Skip to content

Commit b7bd439

Browse files
committed
expand includeInPending logic
1 parent 5ab14fd commit b7bd439

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/Jobs/MigrateDatabase.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ class MigrateDatabase implements ShouldQueue
2020
/**
2121
* Should pending tenants be included while migrating,
2222
* regardless of the tenancy.pending.include_in_queries config value.
23+
*
24+
* If false, pending tenants will be specifically excluded.
25+
*
26+
* If null, default to tenancy.pending.include_in_queries config.
2327
*/
24-
public static bool $includePending = true;
28+
public static ?bool $includePending = true;
2529

2630
public function __construct(
2731
protected TenantWithDatabase&Model $tenant,
@@ -31,7 +35,7 @@ public function handle(): void
3135
{
3236
Artisan::call('tenants:migrate', [
3337
'--tenants' => [$this->tenant->getTenantKey()],
34-
'--with-pending' => static::$includePending,
38+
'--with-pending' => static::$includePending ?? config('tenancy.pending.include_in_queries'),
3539
]);
3640
}
3741
}

src/Jobs/SeedDatabase.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ class SeedDatabase implements ShouldQueue
2020
/**
2121
* Should pending tenants be included while seeding,
2222
* regardless of the tenancy.pending.include_in_queries config value.
23+
*
24+
* If false, pending tenants will be specifically excluded.
25+
*
26+
* If null, default to tenancy.pending.include_in_queries config.
2327
*/
24-
public static bool $includePending = true;
28+
public static ?bool $includePending = true;
2529

2630
public function __construct(
2731
protected TenantWithDatabase&Model $tenant,
@@ -31,7 +35,7 @@ public function handle(): void
3135
{
3236
Artisan::call('tenants:seed', [
3337
'--tenants' => [$this->tenant->getTenantKey()],
34-
'--with-pending' => static::$includePending,
38+
'--with-pending' => static::$includePending ?? config('tenancy.pending.include_in_queries'),
3539
]);
3640
}
3741
}

tests/PendingTenantsTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
expect($fn)->toThrow(QueryException::class);
269269
})->with([true, false]);
270270

271-
test('pending tenant databases can be migrated using a job unless configured otherwise', function (bool $includeInQueries, bool $migrateWithPending) {
271+
test('pending tenant databases can be migrated using a job unless configured otherwise', function (bool $includeInQueries, ?bool $migrateWithPending) {
272272
config([
273273
'tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class],
274274
'tenancy.pending.include_in_queries' => $includeInQueries,
@@ -293,16 +293,17 @@
293293

294294
// MigrateDatabase includes/excludes pending tenants based on its $includePending property,
295295
// regardless of the tenancy.pending.include_in_queries config.
296-
expect(Schema::hasTable('users'))->toBe($migrateWithPending);
296+
expect(Schema::hasTable('users'))->toBe($migrateWithPending ?? $includeInQueries);
297297
})->with([
298298
'include pending in queries' => [true],
299299
'exclude pending from queries' => [false],
300300
])->with([
301301
'migrate with pending' => [true],
302302
'migrate without pending' => [false],
303+
'default to config' => [null],
303304
]);
304305

305-
test('pending tenant databases can be seeded using a job unless configured otherwise', function ($includeInQueries, $seedWithPending) {
306+
test('pending tenant databases can be seeded using a job unless configured otherwise', function (bool $includeInQueries, ?bool $seedWithPending) {
306307
config([
307308
'tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class],
308309
'tenancy.pending.include_in_queries' => $includeInQueries,
@@ -328,13 +329,14 @@
328329

329330
// SeedDatabase includes/excludes pending tenants based on its $includePending property,
330331
// regardless of the tenancy.pending.include_in_queries config.
331-
expect(User::where('email', 'seeded@user')->exists())->toBe($seedWithPending);
332+
expect(User::where('email', 'seeded@user')->exists())->toBe($seedWithPending ?? $includeInQueries);
332333
})->with([
333334
'include pending in queries' => [true],
334335
'exclude pending from queries' => [false],
335336
])->with([
336337
'seed with pending' => [true],
337338
'seed without pending' => [false],
339+
'default to config' => [null],
338340
]);
339341

340342
test('jobs that run before tenants get fully created recognize pending tenants', function () {

0 commit comments

Comments
 (0)