Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 migrate:rollback with --path on artisan CLI

I'm having some roadblock on Laravel 4.

Since I can't make artisan:migrate generate migrations from inner folders of app/database/migrations (ex: app/database/migrations/app1)

I have this on my custom command app:migrate

/* default path */
$this->call('migrate'); 

/* custom path */
$this->call('migrate', array('--path' => 'app/database/migrations/app1')); 

but i also want an app:refresh command which will rollback all the migrations from the custom path then from the default path.. then re migrate and seed everything just like what migrate:refresh --seed does

how do i reverse this? calling:

$this->call('migrate:rollback', array('--path' => 'app/database/migrations/app1'));

will produce an error saying

[InvalidArgumentException]
The "--path" option does not exist.

can somebody help please.

thanks!

like image 811
reikyoushin Avatar asked Aug 25 '13 03:08

reikyoushin


People also ask

How do I rollback migration?

You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements. where n is number of migrations to rollback, counting from latest migration. where xxxxx is the version number of the migration.

Which artisan command is used to migrate a database?

To create a new migration, you can run the make:migration Artisan command and that will bootstrap a new class on your Laravel application, in the database/migrations folder. This class will contain a default boilerplate code.

How do I roll back a seeder in Laravel?

use Undo Seeder for Laravel. When you install UndoSeeder, the following artisan commands are made available: db:seed-undo Undo seeds in the seeds directory. db:seed-refresh Undo seeds run seeds again.


1 Answers

All you have to do is make sure your migration classes can be autoloaded. The easiest way to do so is to add the path to the folder you're keeping them to composer.json's autoload.classmap:

...
"autoload": {
    "classmap": [
        ...
        "app/database/migrations/app1",
    ]
},
like image 137
rmobis Avatar answered Oct 20 '22 00:10

rmobis