ziming / laravel-specific-migrate-fresh
Migrate Fresh for Specific Tables Only
Fund package maintenance!
ziming
Installs: 3 706
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^8.1
- illuminate/contracts: ^9.0||^10.0||^11.0
- spatie/laravel-package-tools: ^1.13.0
- staudenmeir/laravel-migration-views: ^1.6||^1.7
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0||^7.0||^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0||^8.0||^9.0
- pestphp/pest: ^1.21||^2.0
- pestphp/pest-plugin-laravel: ^1.1||^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5||^10.0
- spatie/laravel-ray: ^1.26
README
Want php artisan migrate:fresh
but not drop all the tables? This is for you.
Support me
Donations are welcomed.
Installation
You can install the package via composer:
composer require ziming/laravel-specific-migrate-fresh
You can publish the config file with:
php artisan vendor:publish --tag="specific-migrate-fresh-config"
This is the contents of the published config file:
return [ /* * There are 2 modes 'exclude' and 'include'. * * 'exclude' mode will drop all tables except the tables you specified in the 'excluded_tables' array. * 'include' mode will drop only the tables you specified in the 'included_tables' array. */ 'mode' => env('SPECIFIC_MIGRATE_FRESH_MODE', 'exclude'), /* * This will be used if mode is 'exclude'. * * If mode is 'exclude', the database tables in this array will be excluded * from getting dropped. */ 'excluded_tables' => [ // ], /* * This will be used if mode is 'include'. * * If mode is 'include', only the database tables in this array will be dropped */ 'included_tables' => [ // ], ];
Usage
Go to the config file, choose your preferred mode ('exclude' or 'include').
Fill in the relevant array ('excluded_tables' or 'included_tables').
Go to your migrations and for the tables you do not want to drop, in the up() method, add in a conditional check
to skip the migration if the table still exists. You need to do this so that php artisan migrate
will not
throw an error about the table or column already exist later.
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. * * @return void */ public function up() { if (Schema::hasTable('some_giant_table_i_do_not_want_to_drop')) { return; } Schema::create('some_giant_table_i_do_not_want_to_drop', function (Blueprint $table) { $table->id(); // Other columns } }
And call the command below. The --seed
option is optional.
php artisan migrate:specific-fresh --seed
The end of this command simply just call the php artisan migrate --seed
command at the end.
If you do not want to call your DatabaseSeeder. Leave out --seed
from your command.
php artisan migrate:specific-fresh
Testing
PRs are welcomed on this
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.