The Wayback Machine - https://web.archive.org/web/20210408132925/https://github.com/laravel/framework/pull/36906
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

[8.x] Add anonymous migrations #36906

Open
wants to merge 3 commits into
base: 8.x
from

Conversation

@thiagorb
Copy link
Contributor

@thiagorb thiagorb commented Apr 7, 2021

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:

  • 2019_01_01_000000_add_content_to_posts_table
  • 2020_01_01_000000_remove_content_from_posts_table
  • 2021_01_01_000000_add_content_to_posts_table

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.

@thiagorb thiagorb force-pushed the thiagorb:add-anonymous-migrations branch from 97baded to bf104bd Apr 7, 2021
@crynobone
Copy link
Member

@crynobone crynobone commented Apr 8, 2021

This PR changes some of the framework migrations such as batches, failed_jobs. Is there anyway preventing the app from generating the migration more than once?

image

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 👍🏼 .

@thiagorb
Copy link
Contributor Author

@thiagorb thiagorb commented Apr 8, 2021

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?

@crynobone
Copy link
Member

@crynobone crynobone commented Apr 8, 2021

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 php artisan queue:failed-table more than once since it should generate the same file content with a different timestamp and no longer check for the identical class name as if right now (see above picture).

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
@driesvints
Copy link
Member

@driesvints driesvints commented Apr 8, 2021

I really like this idea. I think @crynobone indeed makes a good point about the duplicate framework shipped migrations.

I believe it would be possible to backport it to 6.x too, in case it is approved.

Laravel 6 is closed for new features.

@taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented Apr 8, 2021

It's a cool feature but yeah I would drop the commit of renaming existing migrations - at least until 9.x.

@driesvints driesvints changed the title Add anonymous migrations [8.x] Add anonymous migrations Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants