fix: QuoteItemCategorySeeder 중복 실행 지원

- insertGetId → updateOrInsert로 변경
- 이미 존재하는 카테고리는 업데이트, 없으면 생성

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-27 15:23:02 +09:00
parent 8a1e78ec72
commit dd8a744d12

View File

@@ -29,17 +29,29 @@ public function run(): void
$parentIds = [];
foreach ($parentCategories as $cat) {
$parentIds[$cat['code']] = DB::table('categories')->insertGetId([
'tenant_id' => $tenantId,
'parent_id' => null,
'code_group' => $codeGroup,
'code' => $cat['code'],
'name' => $cat['name'],
'sort_order' => $cat['sort_order'],
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
]);
// 이미 존재하면 업데이트, 없으면 생성
DB::table('categories')->updateOrInsert(
[
'tenant_id' => $tenantId,
'code_group' => $codeGroup,
'code' => $cat['code'],
],
[
'parent_id' => null,
'name' => $cat['name'],
'sort_order' => $cat['sort_order'],
'is_active' => true,
'updated_at' => $now,
'created_at' => $now,
]
);
// ID 조회
$parentIds[$cat['code']] = DB::table('categories')
->where('tenant_id', $tenantId)
->where('code_group', $codeGroup)
->where('code', $cat['code'])
->value('id');
}
// 2. 절곡품 하위 3개 중간 카테고리 추가
@@ -51,17 +63,29 @@ public function run(): void
$bendingSubIds = [];
foreach ($bendingSubCategories as $cat) {
$bendingSubIds[$cat['code']] = DB::table('categories')->insertGetId([
'tenant_id' => $tenantId,
'parent_id' => $parentIds['BENDING'],
'code_group' => $codeGroup,
'code' => $cat['code'],
'name' => $cat['name'],
'sort_order' => $cat['sort_order'],
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
]);
// 이미 존재하면 업데이트, 없으면 생성
DB::table('categories')->updateOrInsert(
[
'tenant_id' => $tenantId,
'code_group' => $codeGroup,
'code' => $cat['code'],
],
[
'parent_id' => $parentIds['BENDING'],
'name' => $cat['name'],
'sort_order' => $cat['sort_order'],
'is_active' => true,
'updated_at' => $now,
'created_at' => $now,
]
);
// ID 조회
$bendingSubIds[$cat['code']] = DB::table('categories')
->where('tenant_id', $tenantId)
->where('code_group', $codeGroup)
->where('code', $cat['code'])
->value('id');
}
// 3. 기존 세부 항목들의 parent_id 업데이트