Laravel launches migration in the "application / database / migration" folder recursively

So the folder of my migrations looks like this because I have dozens of tables that keep things organized and clean:

migrations/ create_user_table.php relations/ translations/ 

I am trying to update all migrations and samples, but it looks like I encountered a small glitch when I do not know what artisan command is for relaying the migration (i.e. the migration is performed in relations and translations ).

I tried adding --path="app/database/migrations/*" , but it spat out an error. Does anyone know a solution to this?

+22
source share
12 answers

The only way to do this right now is to manually go through all the migrations. That is, you must run the migration command in each of your subfolders:

 php artisan migrate --path=/app/database/migrations/relations php artisan migrate --path=/app/database/migrations/translations 

However, what you can do is easily expand the artisans system to write your own migrate command, which will iterate over all the folders in the migration folder, create these commands for you, and run them.

You can also just write a shell script if you don't want to do this through artisan

Edit: for Laravel> = 5.0, the correct commands for migrating migration files in subdirectories are:

php artisan migrate --path=/database/migrations/relations
php artisan migrate --path=/database/migrations/translations

+37
source

This adds the boot method to the AppServiceProvider

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

Now you can use php artisan migrate as well as php artisan migrate:back

+16
source

You can also use a wildcard, for example:

 php artisan migrate --path=/database/migrations/* 
+11
source

In Laravel 5, the default database folder is next to the application folder. So you can run this to migrate single folder migrations:

 php artisan migrate --path=/database/migrations/users 
+3
source

You can use the following command to do this recursively:

 php artisan migrate --path=/database/migrations/**/* 

**/* also known as globstar

Before this works, you should check to see if your bash supports globalstar. You can do this by running shopt and checking for globstar .

Globstar is by default supported by most server distributions, but may not work on MAC.

For more information about Globstar, see: https://www.linuxjournal.com/content/globstar-new-bash-globbing-option

+2
source

You can try this package nscreed / laravel -igration-paths . By default, all subdirectories within the migration folder will be automatically loaded. Even you can easily add any directories.

 'paths' => [ database_path('migrations'), 'path/to/custom_migrations', // Your Custom Migration Directory ], 

No special commands are needed, only general: php artisan migrate will complete your tasks.

+2
source

This is not a "direct" solution, but I suggest you take a look at the modularity in your laravel project.

Modules can segment your application into several small "folders" and transfer migrations, seeds, classes, routes, controllers, commands together to easily supported folders.

This package is a good start: https://github.com/pingpong-labs/modules

+1
source

A simple Laravel solution is to create a gulp task (say migrate-others ).

 var elixir = require('laravel-elixir'); var gulp = require('gulp'); var shell = require('gulp-shell') /* |-------------------------------------------------------------------------- | Elixir Asset Management |-------------------------------------------------------------------------- | | Elixir provides a clean, fluent API for defining some basic Gulp tasks | for your Laravel application. By default, we are compiling the Sass | file for our application, as well as publishing vendor resources. | */ elixir(function(mix) { mix.sass('app.scss'); }); // Our Task gulp.task('migrate-others', shell.task([ 'php artisan migrate --path=/app/database/migrations/relations', 'php artisan migrate --path=/app/database/migrations/translations', ])); 

Now you can just call

 gulp migrate-others 
0
source

Here you go!

  function rei($folder) { $iterator = new DirectoryIterator($folder); system("php artisan migrate --path=" . $folder); foreach ($iterator as $fileinfo) { if ($fileinfo->isDir() && !$fileinfo->isDot()) { echo $fileinfo->getFilename() . "\n"; rei($folder . $fileinfo->getFilename() . '/'); } } } rei('./database/'); 
0
source

I rewrote MigrationServiceProvider:

 - registerResetCommand() - registerStatusCommand() - registerMigrateCommand() 

Here you can register your own teams:

 class MigrateCommand extends Illuminate\Database\Console\Migrations\MigrateCommand 

After that, you just need to expand the youd directories:

 protected function getMigrationPaths() 

Or you just register the paths when you download the application. I already made my decision before I made a reservation about '$ this-> loadMigrationsFrom'.

0
source

A simple solution is to create an Artisan Command (migrate: all)

then the internal descriptor function defines the migrate command for each subdirectory, as follows.

 Artisan::call('migrate', [ '--path' => '/database/migrations/employee' ]); 
0
source

Only the relative path works for me (in Laravel 5.7):

 php artisan migrate --path=database/migrations/your-folder-with-migrations 
0
source

All Articles