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

Can't provide a path to migrate:rollback #13631

Closed
warrickhill opened this issue May 20, 2016 · 7 comments
Closed

Can't provide a path to migrate:rollback #13631

warrickhill opened this issue May 20, 2016 · 7 comments

Comments

@warrickhill
Copy link

if you run php artisan migrate --path=path/to/migrations the migrations run fine but you can't run php artisan migrate:rollback --path=path/to/migrations

The "--path" option does not exist.

@leesleefeng
Copy link

leesleefeng commented May 20, 2016

Because migrate:rollback is based on the migrations table.
This command undo the latest batch of migrattions, not one.
migrate 2016-5-21

While there is an alternative.
You can do what you want to undo in a new migration file and run migrate.
Since each migration consists of an up and down methods, rollback means run codes in the down method, then in the new migration file, you just write those codes of the down metod in the up method.

Example:

old migration file:

up method:
$table->integer('for_num'); // add for_num field

down method:
$table->drop('for_num'); // delete field

new migration file:
up mtehod:
$table->drop('for_num');

down mthod of the new file can be left blank and do nothing.

.

@mrk-j
Copy link
Contributor

mrk-j commented May 20, 2016

If you run composer dump-autoload this actually works. I tested this as follows:

  • Created a migration in database/migrations/sub/2016_05_20_192337_create_sub_table.php.
  • Then I ran php artisan migrate with output: Migrated: 2016_05_20_192337_create_sub_table.
  • Then I tried php artisan migrate:rollback and got output: [Symfony\Component\Debug\Exception\FatalThrowableError] Fatal error: Class 'CreateSubTable' not found.
  • Then I ran composer dump-autoload and tried the rollback again, with success: Rolled back: 2016_05_20_192337_create_sub_table.

Did you try this?

@minhchu
Copy link

minhchu commented May 26, 2016

@mrk-j it looks like your Laravel isnt working properly. Because after creating migration, Laravel always runs composer dump-autoload in this file

@mrk-j
Copy link
Contributor

mrk-j commented May 26, 2016

@minhchu I just copied another migration to try this, so composer dump-autoload didn't run. I just assumed this was the case. Can you confirm this issue doesn't exist?

@minhchu
Copy link

minhchu commented May 26, 2016

Ah, sorry for the misunderstanding. If you just copied you have to dump autoload so that Laravel can know your migration files.
If you use php artisan make:migration, Laravel dump autoload for you automatically. And I think this is not an issue.
As @leesleefeng explained, that is the default behaviour, we can close this issue.

@billmn
Copy link
Contributor

billmn commented Jun 3, 2016

@warrickhill This issue can be closed?

anderly added a commit to anderly/laravel-framework that referenced this issue Sep 6, 2016
…aravel#13631

Added path support for artisan migrate:rollback/refresh/reset fixed laravel#13631

Add --path support to ResetCommand and RefreshCommand

Add --path to refresh command test.

Update refresh command test.
@anderly
Copy link
Contributor

anderly commented Sep 6, 2016

See my PR above. This is still an issue.

For example, I have a multi-tenant app with one main application/security database and separate tenant databases. I keep tenant migrations stored in a tenant subfolder of the migrations folder. I have a custom Artisan command (php artisan migrate:tenant) which, in turn, calls php artisan migrate for each tenant and passes the --database=tenant option to specify the tenant database connection and the --path option to specify the path to the tenant migrations (i.e. database/migrations/tenant. This works fine and executes the migrations against the tenant database(s), but if I try to run php artisan migrate:rollback --database=tenant, it tries to rollback the migrations in the main migrations folder. So, the --path option was needed on the rollback, refresh and reset commands in order to support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants