From bc77d72ba6e086c5dd76937403d5f4da2e821f62 Mon Sep 17 00:00:00 2001 From: kent Date: Sat, 13 Dec 2025 15:44:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=9D=B4?= =?UTF-8?q?=EA=B4=80=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20null=20=EC=BD=94=EB=93=9C=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - materials.material_code가 null인 경우 자동 코드 생성 (SM-000001 형식) - item_id_mappings 테이블 중복 생성 방지 로직 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- ...31_migrate_products_materials_to_items.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/database/migrations/2025_12_13_152631_migrate_products_materials_to_items.php b/database/migrations/2025_12_13_152631_migrate_products_materials_to_items.php index 3f70e92..a59ce2d 100644 --- a/database/migrations/2025_12_13_152631_migrate_products_materials_to_items.php +++ b/database/migrations/2025_12_13_152631_migrate_products_materials_to_items.php @@ -22,17 +22,21 @@ */ public function up(): void { - // ID 매핑 테이블 생성 - Schema::create('item_id_mappings', function (Blueprint $table) { - $table->id(); - $table->string('source_table', 20)->comment('products or materials'); - $table->unsignedBigInteger('source_id')->comment('원본 테이블 ID'); - $table->unsignedBigInteger('item_id')->comment('items 테이블 ID'); - $table->timestamps(); + // ID 매핑 테이블 생성 (없으면 생성, 있으면 초기화) + if (! Schema::hasTable('item_id_mappings')) { + Schema::create('item_id_mappings', function (Blueprint $table) { + $table->id(); + $table->string('source_table', 20)->comment('products or materials'); + $table->unsignedBigInteger('source_id')->comment('원본 테이블 ID'); + $table->unsignedBigInteger('item_id')->comment('items 테이블 ID'); + $table->timestamps(); - $table->unique(['source_table', 'source_id']); - $table->index('item_id'); - }); + $table->unique(['source_table', 'source_id']); + $table->index('item_id'); + }); + } else { + DB::table('item_id_mappings')->truncate(); + } $productCount = 0; $materialCount = 0; @@ -107,11 +111,17 @@ public function up(): void ->get(); foreach ($materials as $material) { + // NULL 코드 처리: 자동 생성 + $code = $material->material_code; + if (empty($code)) { + $code = sprintf('%s-%06d', $material->material_type, $material->id); + } + // items 테이블에 삽입 $itemId = DB::table('items')->insertGetId([ 'tenant_id' => $material->tenant_id, 'item_type' => $material->material_type, - 'code' => $material->material_code, + 'code' => $code, 'name' => $material->name, 'unit' => $material->unit, 'category_id' => $material->category_id,