muhammadhuzaifa/laravel-safe-migration

The package provide a safest way to run migration commands by generating backup of the database before running the actual migration command.

v1.1.0 2023-05-03 13:08 UTC

This package is auto-updated.

Last update: 2024-04-29 20:50:52 UTC


README

Latest Version on Packagist Total Downloads

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.

Installation

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",
];

Usage

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.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.