Search code examples
phplaraveldatabase-migration

Laravel running migrations on "app/database/migrations" folder recursively


So my migrations folder looks like this since I have dozens of tables it keeps things organized and clean:

migrations/
  create_user_table.php
  relations/
  translations/

I'm trying to do a refresh all migrations and seed but it seems like I've run into a slight hiccup where I don't know the artisan command to run migrations recursively (i.e. run migrations in the relations and translations folders as well).

I've tried adding --path="app/database/migrations/*" however it spat out an error. Does anyone know the solution to this?


Solution

  • The only way to do it right now is to manually go through all the migrations. That is, you have to run the migration command on 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 extend the artisan system to write your own migrate command that will iterate through all folders under the migrations folder, create these commands for you and run them.

    You can also simply write a shell script if you don't want to get into doing this via artisan

    Edit: for Laravel >= 5.0, the correct commands to migrate migration files in sub directories would be:

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