Implements Spec 087: Legacy Runs Removal (rigorous). ### What changed - Canonicalized run history: **`operation_runs` is the only run system** for inventory sync, Entra group sync, backup schedule execution/retention/purge. - Removed legacy UI surfaces (Filament Resources / relation managers) for legacy run models. - Legacy run URLs now return **404** (no redirects), with RBAC semantics preserved (404 vs 403 as specified). - Canonicalized affected `operation_runs.type` values (dotted → underscore) via migration. - Drift + inventory references now point to canonical operation runs; includes backfills and then drops legacy FK columns. - Drops legacy run tables after cutover. - Added regression guards to prevent reintroducing legacy run tokens or “backfilling” canonical runs from legacy tables. ### Migrations - `2026_02_12_000001..000006_*` canonicalize types, add/backfill operation_run_id references, drop legacy columns, and drop legacy run tables. ### Tests Focused pack for this spec passed: - `tests/Feature/Guards/NoLegacyRunsTest.php` - `tests/Feature/Guards/NoLegacyRunBackfillTest.php` - `tests/Feature/Operations/LegacyRunRoutesNotFoundTest.php` - `tests/Feature/Monitoring/MonitoringOperationsTest.php` - `tests/Feature/Jobs/RunInventorySyncJobTest.php` ### Notes / impact - Destructive cleanup is handled via migrations (drops legacy tables) after code cutover; deploy should run migrations in the same release. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #106
133 lines
4.5 KiB
PHP
133 lines
4.5 KiB
PHP
<?php
|
|
|
|
use App\Models\AuditLog;
|
|
use App\Models\BackupItem;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\BackupSet;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Policy;
|
|
use App\Models\PolicyVersion;
|
|
use App\Models\RestoreRun;
|
|
use App\Models\SettingsCatalogCategory;
|
|
use App\Models\SettingsCatalogDefinition;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('purges non-persistent tenant data without touching persistent catalog data', function () {
|
|
$tenantA = Tenant::factory()->create(['name' => 'Tenant A']);
|
|
$tenantB = Tenant::factory()->create(['name' => 'Tenant B']);
|
|
|
|
SettingsCatalogCategory::create([
|
|
'category_id' => 'cat-1',
|
|
'display_name' => 'Account Management',
|
|
'description' => null,
|
|
]);
|
|
|
|
SettingsCatalogDefinition::create([
|
|
'definition_id' => 'def-1',
|
|
'display_name' => 'Deletion Policy',
|
|
'description' => null,
|
|
'help_text' => null,
|
|
'category_id' => 'cat-1',
|
|
'ux_behavior' => null,
|
|
'raw' => [],
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
$policyA = Policy::factory()->create(['tenant_id' => $tenantA->id]);
|
|
$policyB = Policy::factory()->create(['tenant_id' => $tenantB->id]);
|
|
|
|
PolicyVersion::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'policy_id' => $policyA->id,
|
|
'version_number' => 1,
|
|
]);
|
|
|
|
PolicyVersion::factory()->create([
|
|
'tenant_id' => $tenantB->id,
|
|
'policy_id' => $policyB->id,
|
|
'version_number' => 1,
|
|
]);
|
|
|
|
$backupSetA = BackupSet::factory()->create(['tenant_id' => $tenantA->id]);
|
|
BackupItem::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'backup_set_id' => $backupSetA->id,
|
|
'policy_id' => $policyA->id,
|
|
]);
|
|
|
|
RestoreRun::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'backup_set_id' => $backupSetA->id,
|
|
]);
|
|
|
|
AuditLog::create([
|
|
'tenant_id' => $tenantA->id,
|
|
'actor_id' => null,
|
|
'actor_email' => null,
|
|
'actor_name' => null,
|
|
'action' => 'test.action',
|
|
'resource_type' => null,
|
|
'resource_id' => null,
|
|
'status' => 'success',
|
|
'metadata' => null,
|
|
'recorded_at' => now(),
|
|
]);
|
|
|
|
OperationRun::factory()->create([
|
|
'tenant_id' => $tenantA->id,
|
|
'user_id' => $user->id,
|
|
'status' => 'completed',
|
|
]);
|
|
|
|
$scheduleA = BackupSchedule::create([
|
|
'tenant_id' => $tenantA->id,
|
|
'name' => 'Schedule A',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '10:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
'last_run_at' => null,
|
|
'last_run_status' => null,
|
|
'next_run_at' => now()->addHour(),
|
|
]);
|
|
|
|
expect(Policy::query()->where('tenant_id', $tenantA->id)->count())->toBeGreaterThan(0);
|
|
expect(BackupSet::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBeGreaterThan(0);
|
|
expect(OperationRun::query()->where('tenant_id', $tenantA->id)->count())->toBeGreaterThan(0);
|
|
|
|
$this->artisan('tenantpilot:purge-nonpersistent', [
|
|
'tenant' => $tenantA->id,
|
|
'--force' => true,
|
|
'--no-interaction' => true,
|
|
])->assertSuccessful();
|
|
|
|
expect(Policy::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(PolicyVersion::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(BackupItem::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(BackupSet::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(RestoreRun::withTrashed()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(AuditLog::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
expect(OperationRun::query()->where('tenant_id', $tenantA->id)->count())->toBe(1);
|
|
expect(OperationRun::query()
|
|
->where('tenant_id', $tenantA->id)
|
|
->where('type', 'backup_schedule_purge')
|
|
->exists())->toBeTrue();
|
|
|
|
expect(BackupSchedule::query()->where('tenant_id', $tenantA->id)->count())->toBe(0);
|
|
|
|
expect(Policy::query()->where('tenant_id', $tenantB->id)->count())->toBe(1);
|
|
expect(PolicyVersion::withTrashed()->where('tenant_id', $tenantB->id)->count())->toBe(1);
|
|
|
|
expect(SettingsCatalogCategory::query()->count())->toBe(1);
|
|
expect(SettingsCatalogDefinition::query()->count())->toBe(1);
|
|
});
|