Skip to content

[12.x] Allow migrate:status command to filter by status (Ran, Pending, Skipped) #55557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from

Conversation

ziadoz
Copy link
Contributor

@ziadoz ziadoz commented Apr 25, 2025

This PR allows migrations to be filtered by status (Ran, Pending or Skipped) in the migrate:status command via a new --status flag.

This is handy now that Laravel allows migrations to be skipped: #55011

Screenshot 2025-04-25 at 14 08 44

The command now distinguishes between Pending and Skipped:

❯ php artisan migrate:status 

  Migration name .......................................................... Batch / Status  
  0001_01_01_000000_foo .......................................................... [1] Ran  
  0001_01_01_000001_bar .......................................................... Pending  
  0001_01_01_000002_baz .......................................................... Skipped 

The command can be filtered using --status:

❯ php artisan migrate:status --status=pending --status=skipped

  Migration name .......................................................... Batch / Status  
  0001_01_01_000001_bar .......................................................... Pending  
  0001_01_01_000002_baz .......................................................... Skipped

The existing --pending flag is deprecated, but still works as before. It includes Pending and Skipped migrations, to avoid any breaking changes:

❯ php artisan migrate:status --pending

  Migration name .......................................................... Batch / Status  
  0001_01_01_000001_bar .......................................................... Pending  
  0001_01_01_000002_baz .......................................................... Skipped

Also, the command was supposed to return a status code when --pending was used, however that code would never trigger, because $this->option('pending') returns null or false. I've adjusted this so now the return code is 1 (matches) or 0 (no matches), which I assume was the intention.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@ziadoz ziadoz changed the title [12.x] Allow migrate:status command to filter by status (Ran, Pending, Skipped) [12.x] Allow migrate:status command to filter by status Apr 25, 2025
@ziadoz ziadoz changed the title [12.x] Allow migrate:status command to filter by status [12.x] Allow migrate:status command to filter by status (Ran, Pending, Skipped) Apr 25, 2025
@ziadoz ziadoz marked this pull request as ready for review April 25, 2025 12:46
@ziadoz ziadoz marked this pull request as draft April 25, 2025 12:51
@ziadoz ziadoz marked this pull request as ready for review April 25, 2025 14:08
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@ziadoz
Copy link
Contributor Author

ziadoz commented Apr 25, 2025

@taylorotwell Would a simpler PR that only adds the Skipped status, perhaps as Pending (Skipped), in the output be more acceptable?

@ziadoz ziadoz deleted the migration-skipped branch April 25, 2025 15:20
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.

2 participants