I have multiple databases setup. I want to change the default folder for migration run i.e. I want that if I run php artisan migrate
. It should run the new migrations in /database/migrations/master_database
instead of /database/migrations
as I have migrations for child databases in main /database/migrations
folder which I’m successfully running using php artisan migrate --all
.
What I have done in AppServiceProvider:
$masterDatabasePath = database_path('migrations/master_database');
$this->loadMigrationsFrom($masterDatabasePath);
It works but it take migrations from both /database/migrations
and /database/migrations/master_database
folders while I want that it should only take migrations from /database/migrations/master_database
.
Any Idea what I’m doing wrong or how it can be fixed?
3
Answers
I've achieved this by changing core Laravel BaseCommand.php file in:
vendorlaravelframeworksrcIlluminateDatabaseConsoleMigrationsBaseCommand.php
Changings done in getMigrationPaths() function, from this:
To this:
and then define getMasterDatabaseMigrationPath() function in same file:
Try adding this to boot method in
AppServiceProvider
Now you use can
php artisan migrate
and alsophp artisan migrate:back
.