12e8ba0cac
Гостей чистит visitors:prune (воскресенье 03:15 МСК), партиции событий — существующий partitions:drop-expired по новой настройке retention=6 месяцев. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tests\Concerns\SharesSupplierPdo;
|
|
|
|
uses(DatabaseTransactions::class);
|
|
uses(SharesSupplierPdo::class);
|
|
|
|
beforeEach(function () {
|
|
DB::table('site_events')->delete();
|
|
DB::table('site_visitors')->delete();
|
|
});
|
|
|
|
test('гости старше 180 дней удаляются, свежие остаются', function () {
|
|
$old = (string) Str::uuid();
|
|
$fresh = (string) Str::uuid();
|
|
|
|
DB::table('site_visitors')->insert([
|
|
['id' => $old, 'first_seen_at' => now()->subDays(200), 'last_seen_at' => now()->subDays(200)],
|
|
['id' => $fresh, 'first_seen_at' => now()->subDays(10), 'last_seen_at' => now()->subDays(10)],
|
|
]);
|
|
|
|
$this->artisan('visitors:prune')->assertExitCode(0);
|
|
|
|
expect(DB::table('site_visitors')->where('id', $old)->exists())->toBeFalse();
|
|
expect(DB::table('site_visitors')->where('id', $fresh)->exists())->toBeTrue();
|
|
});
|
|
|
|
test('срок хранения настраивается ключом --days', function () {
|
|
$id = (string) Str::uuid();
|
|
DB::table('site_visitors')->insert([
|
|
['id' => $id, 'first_seen_at' => now()->subDays(40), 'last_seen_at' => now()->subDays(40)],
|
|
]);
|
|
|
|
$this->artisan('visitors:prune', ['--days' => 30])->assertExitCode(0);
|
|
|
|
expect(DB::table('site_visitors')->where('id', $id)->exists())->toBeFalse();
|
|
});
|