Skip to content

Commit bc102d3

Browse files
authored
Merge pull request #4 from digital-entropy/patch-perpetual
2 parents 186a011 + 5ecbba6 commit bc102d3

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LARAVEL PATCHER
1+
Laravel Patcher
22
--
33
*A (migration like) patcher for a smoldering production update.* <br>
44

@@ -9,7 +9,7 @@ LARAVEL PATCHER
99
* PHP : 8.\*
1010
* Laravel: 9.\*
1111

12-
### INSTALLATION
12+
### Installation
1313
do either of this methods below.
1414
* via shell
1515
```shell script
@@ -23,16 +23,16 @@ composer require dentro/laravel-patcher
2323
}
2424
}
2525
```
26-
### POST INSTALLATION
26+
### Post Installation
2727
> this process is optional, you can skip it though.
2828
2929
patches table creation.
3030
```shell script
3131
php artisan patcher:install
3232
```
3333

34-
### USAGE
35-
#### CREATE NEW PATCH
34+
### Usage
35+
#### Create New Patch
3636
for creating new patch you just need to run these following command
3737
```shell script
3838
php artisan make:patch what_do_you_want_to_patch
@@ -80,7 +80,7 @@ that you can use for supporting your patch such as:
8080
> ];
8181
> ```
8282
> you can learn more about `\Illuminate\Log\Logger` [here](https://laravel.com/api/8.x/Illuminate/Log/Logger.html)
83-
#### SHOW PATCH STATUS
83+
#### Show Patch Status
8484
```shell script
8585
php artisan patcher:status
8686
```
@@ -95,7 +95,7 @@ Example:
9595
+------+---------------------------------------+-------+
9696
```
9797

98-
#### RUN A PATCH(ES)
98+
#### Run Pending Patch(es)
9999
```shell script
100100
php artisan patcher:run
101101
```
@@ -109,7 +109,7 @@ Patching: 2020_10_09_124616_add_attachment_beep
109109
Patched: 2020_10_09_124616_add_attachment_beep (0.06 seconds)
110110
```
111111

112-
#### SKIPPING THE PATCH
112+
#### Conditional Patch
113113
You might need to skip single patch when run ```php artisan patcher:run```.
114114
Due to patch is unnecessary or patch is not eligible to run in your environment.
115115
Here you can add the ```eligible``` method to your patch class to evaluate the condition
@@ -143,3 +143,14 @@ Skipped: 2020_09_29_190531_fix_double_sections is not eligible to run in curren
143143
Patching: 2020_10_09_124616_add_attachment_beep
144144
Patched: 2020_10_09_124616_add_attachment_beep (0.06 seconds)
145145
```
146+
147+
#### Perpetual Patch
148+
In some cases you might also want to run patches script indefinitely, you can change `isPerpetual`
149+
property on your patch file to `true`
150+
151+
```php
152+
class WhatDoYouWantToPatch extends Patch
153+
{
154+
public bool $isPerpetual = true;
155+
}
156+
```

src/Patch.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ abstract class Patch extends Migration
3737
*/
3838
public $withinTransaction = false;
3939

40+
/**
41+
* Determine if patch should run perpetually.
42+
*
43+
* @var bool
44+
*/
45+
public bool $isPerpetual = false;
46+
4047
/**
4148
* Run patch script.
4249
*

src/Patcher.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ protected function patch(string $file, int $batch): void
6666

6767
$runTime = round(microtime(true) - $startTime, 2);
6868

69-
$this->repository->log($name, $batch);
69+
if (! $patch->isPerpetual) {
70+
$this->repository->log($name, $batch);
71+
}
7072

71-
$this->note("<info>Patched:</info> $name ($runTime seconds).");
73+
$this->note("<info>Patched:</info> $name ($runTime seconds)." . $patch->isPerpetual ? " (Perpetual)" : "");
7274
} else {
7375
$this->note("<comment>Skipped:</comment> $name is not eligible to run in current condition.");
7476
}

0 commit comments

Comments
 (0)