Yii2: migrate/fresh --migrationTable --migrationPath

Created on 8 Apr 2018  路  7Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

/yii migrate/fresh --migrationPath=@app/modules/<module>/migrations --migrationTable=<module>_migrations

What is the expected result?

Run migrate/down for all the migrations in the --migrationPath

What do you get instead?

Deletes all the tables from the database and run migrate/up in --migrationPath

Most helpful comment

@thyseus understood. So
laravel migrate:fresh => yii migrate/fresh
laravel migrate:refresh => yii migrate/redo all

All 7 comments

It was intended to do exactly what it does.

"Are you sure you want to reset the database and start the migration from the beginning?"

What if there are tables generated from multiple migrationPath or migrationNamespaces? Since migration supports migrationPath/migrationNamespaces I think fresh should also respect both.

if you have multple sources the workflow for refresh would be:

./yii migrate/fresh --migrationPath=@app/modules/<module1>/migrations --migrationTable=<module1>_migrations
./yii migrate/up --migrationPath=@app/modules/<module2>/migrations --migrationTable=<module2>_migrations
...

@cebe Understood. But warning message of "actionFresh" says
"Are you sure you want to reset the database and start the migration from the beginning".
Here "start the migration from the beginning" makes no sense. Since it only runs the migrate/up in "migrations" or path specified in migrationPath.

If migrate/fresh use --migrationTable for migrate/up it should use --migrationTable for truncate also.

I suggest changing the "function truncateDatabase()" to the following

$this->interactive = false; $this->actionDown("all");

The developer can also ensure that the rollback (actionDown()) is working properly for all migrations specified in the migrationPath

14664 @thyseus @samdark

When i implemented the migrate/fresh command i had this feature from Laravel 5.5 in mind:

https://laravel-news.com/migrate-fresh

There it says:

What is also beneficial with this new command is [...] it made the up and down methods in migrations optional. Now you can leave off the down and still quickly reset your local database.

Indeed having multiple sources of migrations is not really covered by this feature. I wouldn't mind to change the description sentence of this console command to cover this.

@thyseus understood. So
laravel migrate:fresh => yii migrate/fresh
laravel migrate:refresh => yii migrate/redo all

I suggest changing the "function truncateDatabase()" to the following

$this->interactive = false; $this->actionDown("all");

if you want down all, you can just use that, fresh is different on purpose.

Was this page helpful?
0 / 5 - 0 ratings