Home > Software engineering >  Change default migrations folder
Change default migrations folder

Time:11-03

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?

CodePudding user response:

php artisan make:migration  "create users table" --path=/var/www/html/custom_migration

php artisan migrate --path=/var/www/html/custom_migration

CodePudding user response:

Try adding this to boot method in AppServiceProvider

$mainPath = database_path('migrations');
$directories = glob($mainPath . '/*' , GLOB_ONLYDIR);
$paths = array_merge([$mainPath], $directories);

$this->loadMigrationsFrom($paths);

Now you use can php artisan migrate and also php artisan migrate:back.

  • Related