delete (옛 row 없으면 silent skip) * - renamed 는 신 row 존재 시 silent skip (Migration 에 위임) * * V-1 안전: * - Illuminate\Support\Facades\DB / Schema 만 사용 * - app(*Service|*Manager|*Repository::class) 호출 없음 * - 다른 버전 namespace 참조 없음 * - Database\Seeders 참조 없음 */ final class PermissionsApplier implements SnapshotApplier { public function __construct(private readonly string $jsonPath) {} public function apply(UpgradeContext $context): void { if (! Schema::hasTable('permissions')) { $context->logger->info('[7.0.0-beta.5] permissions 테이블 부재 — PermissionsApplier skip'); return; } $delta = json_decode( file_get_contents($this->jsonPath), true, flags: JSON_THROW_ON_ERROR, ); $now = now(); foreach ($delta['added'] ?? [] as $row) { if (empty($row['identifier'])) { continue; } DB::table('permissions')->updateOrInsert( ['identifier' => $row['identifier']], [ 'type' => $row['type'] ?? null, 'category' => $row['category'] ?? null, 'name' => isset($row['name']) ? json_encode($row['name']) : null, 'updated_at' => $now, 'created_at' => $now, ], ); } foreach ($delta['removed'] ?? [] as $identifier) { DB::table('permissions')->where('identifier', $identifier)->delete(); } $renameApplied = 0; foreach ($delta['renamed'] ?? [] as $rename) { $from = $rename['from'] ?? null; $to = $rename['to'] ?? null; if (! is_string($from) || ! is_string($to)) { continue; } $oldRow = DB::table('permissions')->where('identifier', $from)->first(); $newRow = DB::table('permissions')->where('identifier', $to)->first(); if ($oldRow && ! $newRow) { DB::table('permissions') ->where('id', $oldRow->id) ->update([ 'identifier' => $to, 'updated_at' => $now, ]); $context->logger->info(sprintf( '[7.0.0-beta.5] permissions in-place rename — %s → %s (id=%d, 피벗 자동 보존)', $from, $to, $oldRow->id, )); $renameApplied++; } } if ($renameApplied > 0) { $context->logger->info(sprintf( '[7.0.0-beta.5] PermissionsApplier 완료 — in-place rename %d건 (충돌 경로는 Migration 위임)', $renameApplied, )); } } }