dentro / laravel-patcher
Laravel patch scripts.
Installs: 7 560
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 0
Forks: 3
Open Issues: 0
Requires
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/database: ^9.0|^10.0|^11.0
- illuminate/log: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- mockery/mockery: ^1.4.2
- orchestra/testbench: ^8.0.10|^9.0.3
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
README
A (migration like) patcher for a smoldering production update.
Requirements:
- PHP : 8.*
- Laravel: 9.* / 10.* / 11.*
Installation
Do either of these methods below.
- via shell
composer require dentro/laravel-patcher
- adding
"dentro/laravel-patcher": "^1.0"
tocomposer.json
{ "require": { "dentro/laravel-patcher": "^1.0" } }
Post Installation
this process is optional, you can skip it though.
patches table creation.
php artisan patcher:install
Usage
Create New Patch
for creating a new patch, you need to run these following command
php artisan make:patch what_do_you_want_to_patch
After run that command, you will see new file in patches
folder.
That file will be like:
<?php use Dentro\Patcher\Patch; class WhatDoYouWantToPatch extends Patch { public function patch() { // } }
Method patch
on this file will be filled with your logic.
in Dentro\Patcher\Patch
there is some useful properties
that you can use for supporting your patch such as:
-
$container: \Illuminate\Container\Container
-
$command: \Illuminate\Console\Command
we frequently used
$command
property to print process that we're doing. example:$this->command->warn('i patch something danger!'); $this->command->confirm('do you wish to continue?');
you can learn more about
\Illuminate\Console\Command
here. -
$logger: \Illuminate\Log\Logger
$logger
will store log instorage/logs/patches.log
. if you want to change it, add this line below in yourconfig/logging.php
in channels section.[ 'channels' => [ 'patcher' => [ 'driver' => 'patcher', // you can change me if you want 'path' => storage_path('logs/patches.log'), // change me ], ], ];
you can learn more about
\Illuminate\Log\Logger
here
Show Patch Status
php artisan patcher:status
Example:
➜ php artisan patcher:status +------+---------------------------------------+-------+ | Ran? | Patch | Batch | +------+---------------------------------------+-------+ | Yes | 2020_09_29_190531_fix_double_sections | 1 | | Yes | 2020_10_09_124616_add_attachment_beep | 1 | +------+---------------------------------------+-------+
Run Pending Patch(es)
php artisan patcher:run
Example:
➜ php artisan patcher:run Patches table created successfully. Patching: 2020_09_29_190531_fix_double_sections Patched: 2020_09_29_190531_fix_double_sections (0.03 seconds) Patching: 2020_10_09_124616_add_attachment_beep Patched: 2020_10_09_124616_add_attachment_beep (0.06 seconds)
Conditional Patch
You might need to skip single patch when run php artisan patcher:run
.
Due to patch is unnecessary or patch is not eligible to run in your environment.
Here you can add the eligible
method to your patch class to evaluate the condition
before running the patch
method.
<?php use Dentro\Patcher\Patch; use App\Models\User; class WhatDoYouWantToPatch extends Patch { public function eligible(): bool { return User::query()->where('id', 331)->exists(); } public function patch() { $user = User::query()->find(331); // do something with user. } }
then the output of php artisan patcher:run
will be:
➜ php artisan patcher:run
Patching: 2020_09_29_190531_fix_double_sections
Skipped: 2020_09_29_190531_fix_double_sections is not eligible to run in current condition.
Patching: 2020_10_09_124616_add_attachment_beep
Patched: 2020_10_09_124616_add_attachment_beep (0.06 seconds)
Perpetual Patch
In some cases you might also want to run patches script indefinitely, you can change isPerpetual
property on your patch file to true
class WhatDoYouWantToPatch extends Patch { public bool $isPerpetual = true; }