Skip to content

[4.x] migrate-fresh: show migration output when verbose#1464

Merged
stancl merged 5 commits into
masterfrom
migrate-fresh-verbose-output
Jun 29, 2026
Merged

[4.x] migrate-fresh: show migration output when verbose#1464
stancl merged 5 commits into
masterfrom
migrate-fresh-verbose-output

Conversation

@lukinovec

@lukinovec lukinovec commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Resubmission of #1369 (by @lordofthebrain), changes adapted to v4. Also added a test (passes with the MigrateFresh changes, fails without them).

Summary by CodeRabbit

  • Features

    • Improved tenants:migrate-fresh console output: per-tenant migration messages are now suppressed by default for a cleaner run.
    • When run with -v, per-tenant progress is shown, including the Migrating tenant {tenantKey} message.
  • Tests

    • Added coverage to verify the command is silent by default and displays the Migrating tenant {tenantKey} message only when -v is enabled.

lukinovec and others added 2 commits June 13, 2026 07:59
Don't run tenants:migrate silently by default during migrate-fresh; its
output is shown when the command is run with -v/--verbose.

---------

Co-authored-by: lordofthebrain <f.mangelsdorf@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MigrateFresh now conditionally suppresses tenant migration output by importing NullOutput and selecting an output object based on verbosity in migrateTenant, switching from callSilently() to runCommand(). A test verifies output is suppressed by default and exposed with the -v flag.

Changes

Output suppression in migrate-fresh command

Layer / File(s) Summary
Conditional output based on verbosity
src/Commands/MigrateFresh.php, tests/CommandsTest.php
NullOutput is imported and used in migrateTenant to conditionally suppress command output when not in verbose mode. The method switches from callSilently('tenants:migrate', ...) to runCommand('tenants:migrate', ..., $output) where $output is determined by verbosity. A test verifies output is suppressed by default and exposed when run with the -v flag.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A quiet hop through migrations deep,
When shells are calm, the output sleeps.
A hush of NullOutput keeps the trail,
But -v wakes voices soft and hale,
Tenants march on without a peep.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title accurately summarizes the main change: migrate-fresh now shows migration output in verbose mode.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migrate-fresh-verbose-output

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.

@lukinovec lukinovec marked this pull request as draft June 13, 2026 06:35
Since CI runs tests with -v, it sets SHELL_VERBOSITY to 1, making the tenants:migrate-fresh output always verbose
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.71%. Comparing base (652bc98) to head (6806871).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1464      +/-   ##
============================================
+ Coverage     86.00%   86.71%   +0.70%     
- Complexity     1175     1256      +81     
============================================
  Files           185      186       +1     
  Lines          3429     3710     +281     
============================================
+ Hits           2949     3217     +268     
- Misses          480      493      +13     

☔ View full report in Codecov by Harness.
📢 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.

@lukinovec lukinovec marked this pull request as ready for review June 13, 2026 07:34

@coderabbitai coderabbitai Bot left a comment

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.

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 374-387: Save the original superglobal values before you overwrite
them and restore them conditionally in the finally block instead of always
unsetting; specifically, before setting $_ENV['SHELL_VERBOSITY'] and
$_SERVER['SHELL_VERBOSITY'] to 0, capture their previous values (e.g.
$prevEnvShellVerbosity = array_key_exists('SHELL_VERBOSITY', $_ENV) ?
$_ENV['SHELL_VERBOSITY'] : null and similarly $prevServerShellVerbosity), then
in the finally block: if $prevEnvShellVerbosity is null
unset($_ENV['SHELL_VERBOSITY']) else $_ENV['SHELL_VERBOSITY'] =
$prevEnvShellVerbosity; do the same for $_SERVER['SHELL_VERBOSITY'], and restore
the process environment with putenv('SHELL_VERBOSITY') when the original getenv
was false or putenv("SHELL_VERBOSITY=$shellVerbosity") when it existed; update
the finally block around the Artisan calls accordingly.
🪄 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: f9f9b7c5-d307-435c-a517-07ffc18033af

📥 Commits

Reviewing files that changed from the base of the PR and between 1f2a017 and 90ff8d7.

📒 Files selected for processing (1)
  • tests/CommandsTest.php

Comment thread tests/CommandsTest.php Outdated

@coderabbitai coderabbitai Bot left a comment

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.

♻️ Duplicate comments (1)
tests/CommandsTest.php (1)

377-383: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Restore $_ENV['SHELL_VERBOSITY'] conditionally.

Line 377 collapses “unset” and 0 into the same value, so Line 383 leaves $_ENV['SHELL_VERBOSITY'] defined after the test even when it was absent before. That leaks process state into later tests and can make verbosity-sensitive assertions order-dependent.

Suggested fix
-    $originalVerbosity = $_ENV['SHELL_VERBOSITY'] ?? 0;
+    $hadOriginalVerbosity = array_key_exists('SHELL_VERBOSITY', $_ENV);
+    $originalVerbosity = $_ENV['SHELL_VERBOSITY'] ?? null;
     try {
         $_ENV['SHELL_VERBOSITY'] = 0;

         Artisan::call('tenants:migrate-fresh');
         $defaultOutput = Artisan::output();
     } finally {
-        $_ENV['SHELL_VERBOSITY'] = $originalVerbosity;
+        if ($hadOriginalVerbosity) {
+            $_ENV['SHELL_VERBOSITY'] = $originalVerbosity;
+        } else {
+            unset($_ENV['SHELL_VERBOSITY']);
+        }
     }
🤖 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 377 - 383, The test setup around
Artisan::call('tenants:migrate-fresh') is not restoring $_ENV['SHELL_VERBOSITY']
correctly because it treats an unset value the same as 0. Update the
CommandsTest logic to record whether SHELL_VERBOSITY existed before the test,
then in the finally block either restore its previous value or remove it
entirely if it was originally absent. Keep the fix localized to this test helper
block so later tests do not inherit leaked verbosity state.
🤖 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.

Duplicate comments:
In `@tests/CommandsTest.php`:
- Around line 377-383: The test setup around
Artisan::call('tenants:migrate-fresh') is not restoring $_ENV['SHELL_VERBOSITY']
correctly because it treats an unset value the same as 0. Update the
CommandsTest logic to record whether SHELL_VERBOSITY existed before the test,
then in the finally block either restore its previous value or remove it
entirely if it was originally absent. Keep the fix localized to this test helper
block so later tests do not inherit leaked verbosity state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0b98e734-acfc-48a1-a1c6-73673748d832

📥 Commits

Reviewing files that changed from the base of the PR and between 90ff8d7 and 4f2c452.

📒 Files selected for processing (1)
  • tests/CommandsTest.php

@stancl stancl requested a review from Copilot June 29, 2026 01:59
@stancl stancl changed the title [4.x] migrate-fresh: show migration output when run with verbose [4.x] migrate-fresh: show migration output when verbose Jun 29, 2026

Copilot AI left a comment

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.

Pull request overview

This PR adjusts the tenants:migrate-fresh command so that per-tenant migration output from the nested tenants:migrate invocation is suppressed by default, but becomes visible when the command is run with -v (verbose). It also adds a regression test to validate the default-vs-verbose output behavior.

Changes:

  • Update MigrateFresh::migrateTenant() to route the nested tenants:migrate output either to the current command output (verbose) or to NullOutput (non-verbose).
  • Add a test asserting that "Migrating tenant {tenantKey}" only appears when tenants:migrate-fresh is executed with -v.
  • Add a test workaround for CI verbosity inheritance when calling Artisan commands.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Commands/MigrateFresh.php Conditionally forwards or suppresses nested migration output based on verbosity.
tests/CommandsTest.php Adds coverage for default vs verbose output behavior for tenants:migrate-fresh.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/CommandsTest.php
@stancl stancl merged commit df4be2e into master Jun 29, 2026
15 checks passed
@stancl stancl deleted the migrate-fresh-verbose-output branch June 29, 2026 02:04
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.

3 participants