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

[5.6] Allow "app" migrations to override package migrations #24521

Merged
merged 1 commit into from
Jun 9, 2018
Merged

[5.6] Allow "app" migrations to override package migrations #24521

merged 1 commit into from
Jun 9, 2018

Conversation

fletch3555
Copy link
Contributor

I was recently helping someone out with an issue where the easiest solution was to override a package migration. I know generally you would want to add a new migration that undoes what the package migration is doing "wrong" and then do what you need, but that option wouldn't work in this case. We ran into some issues, though. After copying the package migration to the app's migration folder, we noticed that the package migration was still taking precedence. This seemed counter-intuitive to me, so we dug into why.

What we found is that the Migrator takes a list of migration paths (provided by this method), enumerates the files within those paths, filters out non-migration files, sorts by filename (date), then runs them in order. The problem is that the map/filter functionality is finding the app version, then overwriting it with the package version of the same name. When it goes to run the migrations, it doesn't even acknowledge the presence of the app copy.

Again, I know the likelihood of you needing to do this is low. In either case, however, it got me thinking. What if a package had an identically-named migration for some reason (perhaps maliciously, perhaps coincidentally)? Your app's migration would never run.


Enter the solution. Let's just reorder the migration paths! Most of Laravel's functionality allows for app versions of files to override package versions of files. I see no reason for this to be treated any differently. In fact, being different will likely just lead to confusion, however small the chance of that is.

This was tested locally with a dd($files) here, among other places. With a single migration file duplicated in the app, the only change to that list was which file was loaded. Unfortunately, I don't have screenshots or any other proof, but reproduction should be straightforward enough.

If you have any questions or comments, I'm certainly open to hearing about them. I found no mention of this in the docs, so I'm not sure whether to consider this a bugfix for an undocumented feature, or a feature enhancement.

@taylorotwell taylorotwell merged commit 1cbb54e into laravel:5.6 Jun 9, 2018
@GrahamCampbell GrahamCampbell changed the title Allow "app" migrations to override package migrations [5.6] Allow "app" migrations to override package migrations Jun 9, 2018
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