user2403824
user2403824

Reputation: 1753

How can I run outstanding migrations in laravel4?

this is my problem.

I have a migration 2013_08_25_220444_create_modules_table.php within this path :

app/modules/user/migrations/

I have created a custom artisan command:

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class UsersModuleCommand extends Command {

/**
 * The console command name.
 *
 * @var string
 */
protected $name = 'users:install';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Instala el modulo de usuarios.';

/**
 * Create a new command instance.
 *
 * @return void
 */
public function __construct()
{
    parent::__construct();
}

/**
 * Execute the console command.
 *
 * @return void
 */
public function fire()
{
    echo 'Instalando migraciones de usuario...'.PHP_EOL;
    $this->call('migrate', array('--path' => app_path() . '/modules/user/migrations'));




    echo 'Done.'.PHP_EOL;
}

/**
 * Get the console command arguments.
 *
 * @return array
 */
protected function getArguments()
{
    return array(
        //array('example', InputArgument::REQUIRED, 'An example argument.'),
    );
}

/**
 * Get the console command options.
 *
 * @return array
 */
protected function getOptions()
{
    return array(
        //array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
    );
}

}

In the fire() method, I call the migrate command and also pass an array of options.

then, in my terminal, I run this command:

php artisan users:install

and I this is the output:

Instalando migraciones de usuario... Nothing to migrate. Done.

the problem is that the migrations does not run.

But if I run this command in the terminal:

php artisan migrate --path=app/modules/user/migrations

everything works ok, It runs the migration 2013_08_25_220444_create_modules_table.php

Note: I have registered the artisan command in the app/start/artisan.php file:

Artisan::add(new UsersModuleCommand);

What am I doing wrong ?

sorry for my English :D

Upvotes: 0

Views: 322

Answers (1)

rmobis
rmobis

Reputation: 27002

Notice how the path you passed on the command line is relative to the app root, but the one you passed on your command is absolute? What you should be calling in your command is:

$this->call('migrate', array('--path' => 'app/modules/user/migrations'));

By the way, since you might some day want to rollback these migrations, it is interesting that you add app/modules/user/migrations to your composer.json's classmaps:

composer.json

...
"autoload": {
    "classmap": [
        ...
        "app/modules/user/migrations",
    ]
},

Upvotes: 1

Related Questions