Skip to content
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

feature: discover migrations #153

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

joelbutcher
Copy link

@joelbutcher joelbutcher commented Dec 18, 2024

TL;DR

This PR allows developers to specify whether their package should auto-discover all migrations in their package without having to specify individual file names.

Context – What problem does this solve?

For smaller packages with maybe a handful of migrations, calling hasMigration multiple times (or just hasMigrations once) is trivial and non-invasive.

However for larger packages, or for people using this tool in larger projects (e.g. registering composer modules in a large-scale production application), having to specify the name of every migration that is within a package or module becomes arduous and prone to mistakes

For example, newer developers will not necessarily always remember that each migration must be manually registered in a service provider (especially since Laravel's functionality is to auto-discover migrations).

Solution

This PR allows developers to choose whether or not their package "auto-discovers" its own migrations, by expanding the Package API with a new discoversMigrations method.

Developers and teams can now simply build a new package with as many migrations as they like without needing to remember to manually register the migration:

$package
    ->name('your-package-name')
    ->discoversMigrations();

When this is called, we will assume this is the default and that any calls to hasMigration or hasMigrations can safely be ignored. (If not, then in some scenarios, this would cause duplicate migrations and errors after publishing migrations and running artisan migrate).

$package
    ->name('your-package-name')
    ->hasMigration('create_my_package_tables') // Ignored
    ->hasMigrations(['my_package_tables', 'some_other_migration'])  // Ignored
    ->discoversMigrations();

I've also updated the hasMigrations to call discoversMigrations when no migration names are provided

@erikgaal
Copy link

erikgaal commented Dec 18, 2024

Maybe add a (default) parameter of database/migrations so that you could technically discover it from elsewhere.

Never mind, that folder is already assumed. 🙃

src/PackageServiceProvider.php Outdated Show resolved Hide resolved
src/Package.php Outdated Show resolved Hide resolved
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