-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Add anonymous migrations #36906
Conversation
This PR changes some of the framework migrations such as Also wouldn't think we should change the default stubs on a patch release, but supporting anonymous migrations itself on patch release should be fine if there no breaking change risk 👍🏼 . |
Hey @crynobone ! Yeah, I thought that changing the stubs could be too much, so I added it as a separate commit. We can drop this last commit then. But your preference is to throw if creating a migration with duplicated name instead of anonymous migrations? |
I worry that it potentially causes an issue if developers try to run My guess all framework migration should remain as it is. and maybe ship with separate anonymous migration stubs for 8.x. php artisan make:migration -a create_posts_table --create |
I really like this idea. I think @crynobone indeed makes a good point about the duplicate framework shipped migrations.
Laravel 6 is closed for new features. |
It's a cool feature but yeah I would drop the commit of renaming existing migrations - at least until 9.x. |
Ok. I reverted the commit with the stubs update. |
There is a breaking change by changing the public |
I restored the public method, and created a new protected one for the new implementation. The old method is not being used anymore though. |
Due to backward compatibility, classic migrations (non-anonymous) should have their class name displayed while running migrations with --pretend, instead of the migration name, like anywhere else in the code.
I just pushed one more change, cause I realized that while running
Instead of:
For the anonymous migrations I left it as:
It would be easy to transform the name into
|
@thiagorb this is a fantastic PR. Thanks for your work 👍 |
this should be mandatory in laravel 9 edit: |
hope to merge this #37352 |
Hey, @thiagorb, I just came across this PR after running into exactly the issue you describe: I developed a project migration by migration, had multiple identical migration names, and never noticed until I tried to create a new instance of the application. You saved me some serious pain with this PR, thank you so much. |
Laravel 8 migration not working on different database different migration folder and namespace above folders has same classname file with namesapce |
This would solve #5899.
With this approach, migrations won't have class names anymore (they didn't serve any purpose and cause some tricky to solve issues).
After a project was maintained for a long time, the chance that two migrations were created with the same name is very high. For example, consider the following migrations:
With the current approach, the first and last migration have the same name. After the third migration is created, it is possible to run it just fine, unless you are trying to run all these migrations at the same time (like after creating an empty database, or while running tests). In a project where there were always tests since the beginning this will be barely an inconvenience, but it causes a lot of trouble for a project that has been developed for many years without tests.
With this new approach this won't be a problem, cause the names can be dropped completely. The new Migrator is still able to run named migration classes, so the solution is backward compatible.
I believe it would be possible to backport it to 6.x too, in case it is approved.