Skip to content

Commit d7fbefe

Browse files
committed
Add support for Laravel Telescope.
Signed-off-by: Sacha Telgenhof Oude Koehorst <stelgenhof@gmail.com>
1 parent cbc5aa9 commit d7fbefe

File tree

7 files changed

+106
-1
lines changed

7 files changed

+106
-1
lines changed

docs/all-tasks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ php artisan deploy:list namespace # List all tasks starting with `namespace:`
3333
| `artisan:storage:link` | Execute artisan storage:link |
3434
| `artisan:up` | Disable maintenance mode |
3535
| `artisan:view:clear` | Execute artisan view:clear |
36+
| `artisan:telescope:clear` | Execute artisan telescope:clear |
37+
| `artisan:telescope:prune` | Execute artisan telescope:prune |
3638
| `config:current` | Show current paths |
3739
| `config:dump` | Print host configuration |
3840
| `config:hosts` | Print all hosts |

docs/how-to-telescope.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# How to clear Telescope entries?
2+
3+
If you are using Laravel's Telescope, you might want to clean up Telescope's entry table as data can get accumulated quickly.
4+
5+
Telescope includes two console commands to clean up the entries table:
6+
- `telescope:clean`: this will delete all entries
7+
- `telescope:prune`: this will clear all entries up until a given date/time. By default Telescope will retain entries made in the last 48 hours.
8+
9+
When deploying to a Production environment, you typically don't need to enable Telescope. However, if you use a testing or staging environment for example, you may want to clean the Telescope data with a deployment.
10+
11+
You can use the `artisan:telescope:prune` to prune Telescope data with the following configuration:
12+
13+
```php
14+
// config/deploy.php
15+
16+
'hooks' => [
17+
'ready' => [
18+
// ...
19+
'artisan:telescope:prune',
20+
],
21+
],
22+
```
23+
24+
If you don't need to keep the entries of the last 48 hours, you can use the `artisan:telescope:clear` to entirely clear Telescope's entry table like this:
25+
26+
```php
27+
// config/deploy.php
28+
29+
'hooks' => [
30+
'ready' => [
31+
// ...
32+
'artisan:telescope:clear',
33+
],
34+
],
35+
```
36+

src/LaravelDeployer/Commands/DeployInit.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function allOptions()
7171
$this->builder->add('hooks.build', 'npm:production');
7272
$this->builder->add('hooks.ready', 'artisan:migrate');
7373
$this->builder->add('hooks.ready', 'artisan:horizon:terminate');
74+
$this->builder->add('hooks.ready', 'artisan:telescope:prune');
7475
}
7576

7677
public function welcomeMessage($emoji, $message)
@@ -163,5 +164,20 @@ public function defineAdditionalHooks()
163164
if ($this->confirm('Do you want to terminate horizon after each deployment?')) {
164165
$this->builder->add('hooks.ready', 'artisan:horizon:terminate');
165166
}
167+
168+
$telescope = $this->choice(
169+
'Do you want to clear telescope entries after each deployment?',
170+
[
171+
'No',
172+
'Yes all entries',
173+
'Yes stale entries only',
174+
], 0
175+
);
176+
177+
if ($telescope !== 'No') {
178+
$command = $telescope === 'Yes all entries' ? 'clear' : 'prune';
179+
$this->builder->add('hooks.ready', "artisan.telescope:$command");
180+
}
181+
166182
}
167183
}

src/task/artisan.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@
4545
task('artisan:storage:link', artisan('storage:link', ['min' => 5.3]));
4646

4747
desc('Execute artisan horizon:terminate');
48-
task('artisan:horizon:terminate', artisan('horizon:terminate'));
48+
task('artisan:horizon:terminate', artisan('horizon:terminate'));
49+
50+
desc('Execute artisan telescope:clear');
51+
task('artisan:telescope:clear', artisan('telescope:clear'));
52+
53+
desc('Execute artisan telescope:prune');
54+
task('artisan:telescope:prune', artisan('telescope:prune'));

tests/Features/DeployInitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function it_generates_a_full_config_file_with_forge_defaults()
8080
"artisan:config:cache",
8181
"artisan:migrate",
8282
"artisan:horizon:terminate",
83+
"artisan:telescope:prune",
8384
],
8485
"done" => [
8586
'fpm:reload',

tests/Features/DeployListTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ function it_should_list_all_available_tasks()
4040
$this->assertContains('artisan:storage:link', $output);
4141
$this->assertContains('artisan:up', $output);
4242
$this->assertContains('artisan:view:clear', $output);
43+
$this->assertContains('artisan:telescope:clear', $output);
44+
$this->assertContains('artisan:telescope:prune', $output);
4345

4446
// Config
4547
$this->assertContains('config:current', $output);

tests/Unit/ConfigFileBuilderTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,46 @@ function it_returns_current_values_of_configs()
212212

213213
$this->assertEquals('some/repository.git', $repo);
214214
}
215+
216+
/** @test */
217+
function it_can_be_set_to_clear_telescope_entries()
218+
{
219+
$config = (new ConfigFileBuilder)
220+
->add('hooks.ready', 'artisan:telescope:clear')
221+
->build();
222+
223+
$this->assertArraySubset(
224+
['hooks' => [
225+
'ready' => [
226+
'artisan:storage:link',
227+
'artisan:view:clear',
228+
'artisan:cache:clear',
229+
'artisan:config:cache',
230+
'artisan:telescope:clear',
231+
],
232+
]],
233+
$config->toArray()
234+
);
235+
}
236+
237+
/** @test */
238+
function it_can_be_set_to_prune_telescope_entries()
239+
{
240+
$config = (new ConfigFileBuilder)
241+
->add('hooks.ready', 'artisan:telescope:prune')
242+
->build();
243+
244+
$this->assertArraySubset(
245+
['hooks' => [
246+
'ready' => [
247+
'artisan:storage:link',
248+
'artisan:view:clear',
249+
'artisan:cache:clear',
250+
'artisan:config:cache',
251+
'artisan:telescope:prune',
252+
],
253+
]],
254+
$config->toArray()
255+
);
256+
}
215257
}

0 commit comments

Comments
 (0)