Skip to content

added migration file check before publish passport-migration #1831

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 4 commits into from

Conversation

tareqsifat
Copy link

@tareqsifat tareqsifat commented Jun 16, 2025

Laravel Passport: Prevent Duplicate Migration Files

✨ Summary

This pull request improves the behavior of the passport:install command by adding a check to avoid re-publishing Passport migration files if they already exist in the database/migrations directory.


🥉 Problem

When running php artisan passport:install on a fresh Laravel setup using Laragon's Cmder terminal, the following error occurred:

LogicException
Choice question must have at least 1 choice available.

After troubleshooting, Attempting to rerun the command after partial execution led to duplicate migration files and migration errors.


✅ Solution

This PR introduces a pre-check before publishing Passport migration files. It ensures the command:

$this->call('vendor:publish', ['--tag' => 'passport-migrations']);

...is only executed if the Passport migration files don't already exist.

Migration Check Logic

$migrationFilesExist = collect(glob(database_path('migrations/*_create_oauth_*.php')))->isNotEmpty();

if (! $migrationFilesExist) {
    $this->call('vendor:publish', ['--tag' => 'passport-migrations']);
} else {
    $this->components->info('Passport migration files already exist. Skipping publishing...');
}

🧹 Code Clean-up

  • Removed unused imports (DB and Schema) for cleaner code and to pass static analysis.

🎯 Benefits

  • ✅ Prevents accidental duplication of migration files
  • ✅ Ensures safer and more predictable CLI execution
  • ✅ Avoids migration class name conflicts
  • ✅ Improves developer experience (DX) by being idempotent
  • ✅ Aligns with Laravel's philosophy of intuitive tooling

🌟 Notes

This enhancement is fully backward compatible. Existing users of passport:install will now benefit from an extra safeguard against duplicate migrations without needing to change their workflow.


Thanks for reviewing this PR! Looking forward to your feedback and suggestions.

@hafezdivandari
Copy link
Contributor

#1729 (comment)

@tareqsifat
Copy link
Author

@hafezdivandari I've also try to run the command passport:install once, but I got an error. so that I run again

@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!

@vgavrilovikj
Copy link

vgavrilovikj commented Jun 23, 2025

@taylorotwell when running "php artisan passport:client --password" (v13.0.5) I get the error:
LogicException
Choice question must have at least 1 choice available.

The issue is from v13.0.0 - there's no issue in v12.4.2

@hafezdivandari
Copy link
Contributor

@vgavrilovikj
Copy link

@vgavrilovikj did you complete the setup? https://laravel.com/docs/12.x/passport#:~:text=Finally%2C%20in%20your,incoming%20API%20requests

Sorry! Seems like at the time of testing the 'api' guard was missing in the auth.php

All is working good now - thank you!

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