From b7bd439a9d4f72b6c587cdace59c8f2922688bd2 Mon Sep 17 00:00:00 2001 From: Samuel Stancl Date: Fri, 5 Jun 2026 15:09:50 -0700 Subject: [PATCH] expand includeInPending logic --- src/Jobs/MigrateDatabase.php | 8 ++++++-- src/Jobs/SeedDatabase.php | 8 ++++++-- tests/PendingTenantsTest.php | 10 ++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Jobs/MigrateDatabase.php b/src/Jobs/MigrateDatabase.php index b0746da4..b090b70a 100644 --- a/src/Jobs/MigrateDatabase.php +++ b/src/Jobs/MigrateDatabase.php @@ -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'), ]); } } diff --git a/src/Jobs/SeedDatabase.php b/src/Jobs/SeedDatabase.php index 07aa0483..85058b5d 100644 --- a/src/Jobs/SeedDatabase.php +++ b/src/Jobs/SeedDatabase.php @@ -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'), ]); } } diff --git a/tests/PendingTenantsTest.php b/tests/PendingTenantsTest.php index c2886008..b04f8bc4 100644 --- a/tests/PendingTenantsTest.php +++ b/tests/PendingTenantsTest.php @@ -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 () {