Skip to content

[4.x] Add --skip-tenants option to HasTenantOptions#1436

Open
jimish-gamit wants to merge 6 commits intoarchtechx:masterfrom
jimish-gamit:feat/skip-tenants
Open

[4.x] Add --skip-tenants option to HasTenantOptions#1436
jimish-gamit wants to merge 6 commits intoarchtechx:masterfrom
jimish-gamit:feat/skip-tenants

Conversation

@jimish-gamit
Copy link
Copy Markdown

@jimish-gamit jimish-gamit commented Mar 2, 2026

Summary

Adds a --skip-tenants option to all tenant artisan commands (tenants:run, tenants:migrate, tenants:rollback, tenants:seed, tenants:up, tenants:down).

The option is the complement of the existing --tenants option instead of specifying which tenants to include, you specify which to exclude.

Changes

  • src/Concerns/HasTenantOptions.php Added --skip-tenants=* option to getOptions() and a whereNotIn clause in getTenantsQuery() to exclude the specified tenants from the query. Since all tenant commands share this trait, the option is available across all of them.
  • src/Commands/Run.php Added --skip-tenants=* to the command signature so it appears in tenants:run --help.

Usage

# Works on all tenant commands
php artisan tenants:migrate --skip-tenants=tenant3

Summary by CodeRabbit

Release Notes

  • New Features
    • Added --skip-tenants option to tenant commands, enabling you to exclude specific tenants from execution
    • --skip-tenants can be combined with --tenants for precise control over which tenants are affected by console operations

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.89%. Comparing base (8f3ea62) to head (00f4e9f).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1436      +/-   ##
============================================
- Coverage     86.08%   85.89%   -0.19%     
- Complexity     1148     1168      +20     
============================================
  Files           184      185       +1     
  Lines          3363     3410      +47     
============================================
+ Hits           2895     2929      +34     
- Misses          468      481      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jimish-gamit jimish-gamit marked this pull request as draft March 2, 2026 07:14
@jimish-gamit jimish-gamit marked this pull request as ready for review March 2, 2026 08:06
@gjimish
Copy link
Copy Markdown

gjimish commented Mar 7, 2026

Hi @stancl

Just checking in on this PR. Let me know if there’s any feedback or changes needed from my side, happy to update it.

Thanks for your time!

@stancl stancl changed the title [Feature] --skip-tenants option to tenant commands [4.x] Add --skip-tenants option to HasTenantOptions Mar 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

The pull request adds a --skip-tenants command-line option to tenant-aware Artisan commands, enabling users to exclude specific tenants from command execution. The option is registered in the HasTenantOptions trait and filters tenants via a whereNotIn clause in the tenant query, while the Run command signature is updated and test coverage is added.

Changes

Tenant Skipping Functionality

Layer / File(s) Summary
Option Registration & Query Filtering
src/Concerns/HasTenantOptions.php
Trait registers skip-tenants option via getOptions() and adds a conditional whereNotIn() filter in getTenantsQuery() to exclude specified tenant keys from results.
Command Signature
src/Commands/Run.php
tenants:run command signature updated to document the new {--skip-tenants=*} option.
Tests
tests/CommandsTest.php
Three parameterized Pest tests added: (1) migrate commands skip specified tenants, (2) run command omits skipped tenants from output, and (3) combined --tenants and --skip-tenants options correctly exclude tenants present in both.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 A hop and a skip through tenant land,
Where commands now dance at your command—
Skip the ones you don't need to grind,
Let the rest process, peace of mind! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a --skip-tenants option to HasTenantOptions trait, which is the core feature implemented across the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/CommandsTest.php`:
- Around line 519-540: The pest()->artisan(...) invocation in the test closure
(the migrate commands test that creates tenant1/2/3) lacks an exit-code
assertion; modify the call to chain an assertion (for example
->assertExitCode(0) or ->assertSuccessful()) onto the pest()->artisan(...)
expression so the test fails if the artisan command crashes before the
subsequent tenancy/schema expectations run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4729a91a-4d8b-45e5-8b47-efbd6a742e1e

📥 Commits

Reviewing files that changed from the base of the PR and between 8f3ea62 and 00f4e9f.

📒 Files selected for processing (3)
  • src/Commands/Run.php
  • src/Concerns/HasTenantOptions.php
  • tests/CommandsTest.php

Comment thread tests/CommandsTest.php
Comment on lines +519 to +540
test('migrate commands can skip specified tenants', function (string $command) {
$tenant1 = Tenant::create();
$tenant2 = Tenant::create();
$tenant3 = Tenant::create();

pest()->artisan("{$command} --skip-tenants={$tenant1->getTenantKey()} --skip-tenants={$tenant2->getTenantKey()}");

tenancy()->initialize($tenant1);

expect(Schema::hasTable('users'))->toBeFalse();

tenancy()->initialize($tenant2);

expect(Schema::hasTable('users'))->toBeFalse();

tenancy()->initialize($tenant3);

expect(Schema::hasTable('users'))->toBeTrue();
})->with([
'tenants:migrate',
'tenants:migrate-fresh',
]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Missing exit-code assertion on the artisan() call.

Unlike the other two new tests (lines 551, 564), this pest()->artisan(...) call has no ->assertExitCode(0) (or ->assertSuccessful()). A command crash would go undetected if the schema assertions still happen to pass.

✅ Proposed fix
-    pest()->artisan("{$command} --skip-tenants={$tenant1->getTenantKey()} --skip-tenants={$tenant2->getTenantKey()}");
+    pest()->artisan("{$command} --skip-tenants={$tenant1->getTenantKey()} --skip-tenants={$tenant2->getTenantKey()}")
+        ->assertExitCode(0);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/CommandsTest.php` around lines 519 - 540, The pest()->artisan(...)
invocation in the test closure (the migrate commands test that creates
tenant1/2/3) lacks an exit-code assertion; modify the call to chain an assertion
(for example ->assertExitCode(0) or ->assertSuccessful()) onto the
pest()->artisan(...) expression so the test fails if the artisan command crashes
before the subsequent tenancy/schema expectations run.

@stancl stancl self-assigned this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants