Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 4 artisan -- how to rollback to a specific migration state?

Say i got a.php, b.php, c.php and d.php migration classes files. How to rollback to a specific migration state, the state defined within b.php for example, with artisan command ?

like image 520
do. Avatar asked Jul 17 '13 10:07

do.


People also ask

What is php artisan migrate rollback?

php artisan migrate:rollback. You may roll back a limited number of migrations by providing the step option to the rollback command. For example, the following command will roll back the last five migrations: php artisan migrate:rollback --step=5.


2 Answers

I am afraid, you cannot do this directly.

You can: 1, Rollback The Last Migration Operation (all migrations ran in the last batch)

php artisan migrate:rollback 

2, Rollback all migrations

php artisan migrate:reset 

3, Rollback all migrations and run them all again

php artisan migrate:refresh   php artisan migrate:refresh --seed 

In your situation, modify b.php and it's up() method, then execute artisan migrate:refresh command.

like image 168
Andreyco Avatar answered Sep 18 '22 10:09

Andreyco


There's a way to hack it by manually editing the database. In the migrations table change the batch column by giving the last migration a different batch number. Be aware that they are in increasing order, so edit accordingly. This tracks which migrations were applied separately.

Then run artisan:rollback and it will undo the last "batch".

So if you want to separate them all, then start from the top and give each 1,2,3,4,5 and so on... You can see that it is easily scriptable, and you can make an artisan command if you wish to separate all your migrations.

like image 24
Paul Cristea Avatar answered Sep 18 '22 10:09

Paul Cristea