-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[Request] migrate:single and migrate:separate #2085
Comments
An alternative would be using flags, such as |
I like the idea. |
Just not enough demand or use for a feature like this at the moment. |
It would be really handy when it comes to develop module based large applications! 'php artisan migrate --separate' |
I would appreciate this feature |
Looking forward to this. This is a much needed feature as seen from http://stackoverflow.com/questions/19102197/running-one-specific-laravel-4-migration-single-file |
Not sure how much demand is needed, but I would like this too. |
Hi! |
@amoseev +1. I have the same issue here. When doing changes to my app, I needed to do one migration first, then run the seeder and then do the second migration. Yeah, it works well on my local cause i do those steps, but as soon as i pushed to testing environment i came to that problem. Maybe someone knows better workaround. |
this is good idea 👍 there are seeds but sometimes it is not that simple - when your data must be created with other actions as well |
👍 in order to debug a single possibly broken migration out of all the ones that need to run |
Same here, it would be very handy to manage multiple migrations in new app deployment with a bunch of migrations |
I think that this is a very good idea. I would like to see this feature too. |
If this existed, it would help me with this problem: https://laracasts.com/discuss/channels/laravel/ordering-issues-with-laravel-migrations-and-gitflow. I could write some sort of bash script to look at the "missing" migrations (using php artisan migrate:status) and just run those. I think this a fairly common scenario with any team size greater than 1 that uses GitFlow. |
Can't you use |
What happens if there was data created after the migration? This actually happened to us. Migration 20161026 creates a new table I am now forced to rollback 20161026, destroying the data QA created just so I can run 20161024. What if the migration is 2 or 3 back? I may have to rollback multiple migrations, destroying any data along the way. The problem is with processes like GitFlow, there is no guarantee that migrations are merged in order. It would seems much simpler to just allow you to run any migrations, that have not been run. I wouldn't do this in production, but I would sure use it in QA. |
I think a quick fix is to protected existing tables when you run
|
I would like to see a So in effect, without this option, im having to develop many seed files. |
I am +1 who needs such feature |
+1 php artisan migrate:refresh --table=some_table |
You can achieve this with this gist https://gist.github.com/rohitkhatri/a3b1237925b609bf7070f924d37b9b92 |
I also saw how you can edit the batch column in the migrate table, if you change the batch number on the row that you want to change, to the highest number, only that table will be rolled back when you do a |
+1 |
I copied @rohitkhatri's gist a little create migrate:batch: https://gist.github.com/daraul/6902e56b39d49bbd762f80525f399b30 You can just run the command to run the next migration in it's own batch. You can pass a batch size, and can also migrate in steps. I tried allowing it to also rollback migrations, but I was too lazy. It can refresh the database, though. |
Any idea to add this to laravel in 2018/2019 as a lot of people want this? |
There is no such command @taylorotwell |
This is very easy to use. |
I would find this very useful for my foreign keys. I have one separate migrations file for all my foreign keys. It would be nice if somebody could tell me how I could reverse the migrations and rerun them. |
Would be great if at least there would be a way to perform 1 migration at a time. In my case I have to change database structure after it has been populated with orders data. Doing it manually is possible, but can have unexpected results. It would be so much easier to write done all changes step by step. Execute 1 migration, then execute couple queries to update data, than execute following migration for example to add a foreign key to a table. |
@taylorotwell Will this ever be implemented? This kind of feature is quite popular amongst other PHP frameworks. |
I'm going to add my +1 to this in 2021 :-) Quick and dirty solution is to use a custom command: Command line: Edit the created file: import DB at the top: create signature: the good stuff:
Run all of your migrations, then run the command we created 'php artisan migrate:singles'. Check it with 'migrate:status' and roll back individually to your hearts content. If you migrate a new batch all at once, just re-run to make then separate again :-) Rolling back even works where there are jumps in the batch numbers! |
I want this feature too. |
To my knowledge, there is currently no way to run migrations as single, or separate batches, such as when testing to see if migrations are working, like when using a set of pre-made migrations in the
app/database/migrations
folder.The only way to do so is to manually move migrations out of the migrations folder, and then move each migration in, run
php artisan migrate
and so on.This has the potential for user error, since the user might accidentally not move the chronologically oldest migration, which could cause unpredictable results.
Another reason to want to have migrations divided into separate batches is when testing rollbacks, since it lets you rollback just the last migration.
Currently doing so requires the user to manually edit the batch number in the migrations table, which also has the potential for user error and unpredictable results.
Therefore I would like to suggest the addition of two commands:
php artisan migrate:single
- migrates the chronologically oldest migration as a new batch. Equivalent to runningphp artisan migrate
with just that single migration in the migrations folder. Note: I am NOT requesting the ability to migrate a single specific migration, since that would go against the principle that they have to be chronological.php artisan migrate:separate
- migrates all available migrations in one command, but does so as individual batches. Equivalent to runningphp artisan migrate
, but the resulting migrations table will show each migration as a separate batch.Other potential suggestion:
migrate:batch 4
- runs the next 4 available migrations as a single batch. Equivalent to runningphp artisan migrate
with only the 4 chronologically oldest migrations. Since it is equivalent it would not error out if there are less than 4, it just stops after reaching 4 migrations.The text was updated successfully, but these errors were encountered: