The package provides safest way to run migration by generating backup of the database each time before the monitorable command probably the migrate*
command is executed.
The laravel-safe-migration
package feature for generating backup is build on top of spatie/laravel-backup package.
You can install the package via composer:
composer require muhammadhuzaifa/laravel-safe-migration
You can publish the config file with:
php artisan vendor:publish --tag="safe-migration-config"
This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Safe Migration Enabled
|--------------------------------------------------------------------------
|
| This value enable or disable the package functionality.
|
*/
"safe_migration_enabled" => env('SAFE_MIGRATION_ENABLED', true),
/*
|--------------------------------------------------------------------------
| Commands To Monitor
|--------------------------------------------------------------------------
|
| This value determined which commands package should listen to
| make database backup before executing it.
|
*/
"commands_to_monitor" => [
"migrate",
'migrate:fresh',
'migrate:refresh',
'migrate:reset',
'migrate:rollback',
],
/*
|--------------------------------------------------------------------------
| Stop On Fail
|--------------------------------------------------------------------------
|
| This value determined whether the migration should continue or not if the
| backup creation fail.
|
*/
"stop_on_fail" => true,
/*
|--------------------------------------------------------------------------
| Filename
|--------------------------------------------------------------------------
|
| You can set the filename here. Timestamp and the extension will be appended
| during the generation of the backup.
|
*/
"filename" => "safe-migration",
];
Once the package is installed and monitorable commands are configured under the config/safe-migration.php
file. Each time you execute the monitorable command, the package will generate a backup file on the local
disk by default. The backups can be found at storage/app/Laravel
. You can customize the disks and other options using spatie config/backup.php
file.
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.