Skip to content

Provide conditional method check before run single patch #1

@muhajirinlpu

Description

@muhajirinlpu

Example syntax

use Dentro\Patcher\Patch;

return new class extends Patch
{
    /**
     * Run patch script.
     *
     * @return void
     */
    public function patch(): void
    {
        //
    }
    
    public function eligible(): boolean
    {
        return false;
    }
};

If eligible() method return false. the patch method will not be called. The output of console will seems like

Patching: 2020_10_09_124616_add_attachment_beep
Skipped: 2020_10_09_124616_add_attachment_beep is not eligible to run in current condition

The reason why we need this :

Patches are often created because of some condition on certain environment, E.g. The staging environment database was broken due to some mistake by developer. But, other developer environments and production are not effected with the bug. So we only need to run this patch on staging environment and in other environments we still can run artisan patcher:run without worry about the error Model with id blablabla not found... that written in patch method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions