fix:AI 메뉴 시더 - AI설정 이동 로직 추가 (서버 배포용)

- AI 관리 부모 그룹 생성
- AI 설정 메뉴를 기존 위치에서 AI 관리 그룹으로 이동
- AI 토큰 사용량 메뉴 생성 또는 이동
- 멱등성 보장 (재실행 안전)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-07 11:11:35 +09:00
parent 1d12a75ac7
commit a882e1f8f9

View File

@@ -11,16 +11,16 @@ public function run(): void
{
$tenantId = 1;
// AI 관리 부모 그룹 찾기 또는 생성
$parentMenu = Menu::withoutGlobalScopes()
// 1. AI 관리 부모 그룹 찾기 또는 생성
$aiGroup = Menu::withoutGlobalScopes()
->where('tenant_id', $tenantId)
->where('name', 'AI 관리')
->whereNull('parent_id')
->whereNull('deleted_at')
->first();
if (! $parentMenu) {
$parentMenu = Menu::withoutGlobalScopes()->create([
if (! $aiGroup) {
$aiGroup = Menu::withoutGlobalScopes()->create([
'tenant_id' => $tenantId,
'parent_id' => null,
'name' => 'AI 관리',
@@ -29,42 +29,63 @@ public function run(): void
'sort_order' => 12,
'is_active' => true,
]);
$this->command->info("AI 관리 부모 그룹 생성 완료 (id: {$parentMenu->id})");
$this->command->info("AI 관리 부모 그룹 생성 완료 (id: {$aiGroup->id})");
} else {
$this->command->info("AI 관리 부모 그룹 이미 존재 (id: {$aiGroup->id})");
}
// AI 토큰 사용량 메뉴 존재 확인
$existingMenu = Menu::withoutGlobalScopes()
// 2. AI 설정 메뉴를 AI 관리 그룹으로 이동 (다른 그룹에 있는 경우)
$aiConfig = Menu::withoutGlobalScopes()
->where('tenant_id', $tenantId)
->where('name', 'AI 토큰 사용량')
->where('parent_id', $parentMenu->id)
->where('name', 'AI 설정')
->whereNull('deleted_at')
->first();
if ($existingMenu) {
$this->command->info('AI 토큰 사용량 메뉴가 이미 존재합니다.');
if ($aiConfig && $aiConfig->parent_id !== $aiGroup->id) {
$aiConfig->update([
'parent_id' => $aiGroup->id,
'sort_order' => 1,
]);
$this->command->info("AI 설정 메뉴를 AI 관리 그룹으로 이동 완료");
} elseif (! $aiConfig) {
$this->command->warn("AI 설정 메뉴가 존재하지 않습니다. (건너뜀)");
} else {
$maxSort = Menu::withoutGlobalScopes()
->where('parent_id', $parentMenu->id)
->whereNull('deleted_at')
->max('sort_order') ?? 0;
$this->command->info("AI 설정 메뉴가 이미 AI 관리 그룹에 있습니다.");
}
// 3. AI 토큰 사용량 메뉴 생성 또는 이동
$aiToken = Menu::withoutGlobalScopes()
->where('tenant_id', $tenantId)
->where('name', 'AI 토큰 사용량')
->whereNull('deleted_at')
->first();
if ($aiToken && $aiToken->parent_id !== $aiGroup->id) {
$aiToken->update([
'parent_id' => $aiGroup->id,
'sort_order' => 2,
]);
$this->command->info("AI 토큰 사용량 메뉴를 AI 관리 그룹으로 이동 완료");
} elseif (! $aiToken) {
Menu::withoutGlobalScopes()->create([
'tenant_id' => $tenantId,
'parent_id' => $parentMenu->id,
'parent_id' => $aiGroup->id,
'name' => 'AI 토큰 사용량',
'url' => '/system/ai-token-usage',
'icon' => 'brain-circuit',
'sort_order' => $maxSort + 1,
'sort_order' => 2,
'is_active' => true,
]);
$this->command->info('AI 토큰 사용량 메뉴 생성 완료');
$this->command->info("AI 토큰 사용량 메뉴 생성 완료");
} else {
$this->command->info("AI 토큰 사용량 메뉴가 이미 AI 관리 그룹에 있습니다.");
}
// 결과 출력
$this->command->info('');
$this->command->info('=== AI 관리 하위 메뉴 ===');
$children = Menu::withoutGlobalScopes()
->where('parent_id', $parentMenu->id)
->where('parent_id', $aiGroup->id)
->whereNull('deleted_at')
->orderBy('sort_order')
->get(['name', 'url', 'sort_order']);