Laravel Batch Migration
it can batch to the database migration., (*1)
Required:
* laravel 5.3 or later.
* php 7 or later., (*2)
Situation
Sometimes, your project's migration want to separate folders, but you need
to add option --path=database/migrations/someone/ or others, that's good but
I want to more automatic. Imagine one command to do all migration or rollback, that's it., (*3)
For example, I have 2 directories in database/migrations:
database/
migrations/
testing1/
create_posts_table.php
create_comment_table.php
testing2/
create_articles_table.php
create_messages_table.php, (*4)
And then you run php arisan migrate:batch it will do all migration done., (*5)
Installation
As others package, use composer install this package. For example:, (*6)
``` bash
$ composer require mombuyish/laravel-batch-migrations, (*7)
Secondly, you need to register service provider in `config/app.php`.
``` php
'providers' => [
...
/*
* Package Service Providers...
*/
Mombuyish\BatchMigration\BatchMigrationServiceProvider::class,
...
Thirdly, Going to app/Console/Kernel.php, adding console command., (*8)
``` php
protected $commands = [
\Mombuyish\BatchMigration\Commands\BatchMigration::class,
\Mombuyish\BatchMigration\Commands\RollbackBatchedMigration::class
];, (*9)
Fourthly, publish config.
``` bash
$ php artisan vendor:publish --provider="Mombuyish\BatchMigration\BatchMigrationServiceProvider"
You can do configure on config batch-migration.php, (*10)
return [
/**
* Accessible paths.
*/
'path' => 'database/migrations',
];
Finally, you can checkout $ php artisan and you can see 2 commands., (*11)
bash
migrate:batch Run the database migrations (including depth dictionaries)
migrate:batch-rollback Rollback the last database migration (including depth directories)
* When you run php artisan migrate:batch, it will do all migrate in path.
* When you run php artisan migrate:batch-rollback, it will rollback your migrate:batch done., (*12)
Supported --force, (*13)
Notice
When you run rollback, maybe it got errors, For know, you need specific directory.
php artisan migrate:rollback --path=database/migrations/someone., (*14)