From 121c888c7c615e9850f168761d2b734762ca005a Mon Sep 17 00:00:00 2001 From: hskwon Date: Mon, 19 Jan 2026 13:19:18 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=8B=A4=ED=96=89=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A9=B1=EB=93=B1=EC=84=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 작업지시 관련 마이그레이션 파일명 날짜 수정 (의존성 순서 해결) - 2025_01_08 → 2025_12_26_100400 (tenant_id 추가) - 2025_01_09 → 2025_12_26_100600 (assignees 테이블) - 2025_01_09 → 2025_12_26_183200 (process_type → process_id) - process_type → process_id 마이그레이션에 멱등성 체크 추가 - 컬럼 존재 여부 확인 (Schema::hasColumn) - FK 존재 여부 확인 (information_schema 쿼리) --- ...dd_tenant_id_to_work_order_sub_tables.php} | 0 ...600_create_work_order_assignees_table.php} | 0 ...ork_orders_process_type_to_process_id.php} | 50 ++++++++++++------- 3 files changed, 32 insertions(+), 18 deletions(-) rename database/migrations/{2025_01_08_100000_add_tenant_id_to_work_order_sub_tables.php => 2025_12_26_100400_add_tenant_id_to_work_order_sub_tables.php} (100%) rename database/migrations/{2025_01_09_100000_create_work_order_assignees_table.php => 2025_12_26_100600_create_work_order_assignees_table.php} (100%) rename database/migrations/{2025_01_09_100000_change_work_orders_process_type_to_process_id.php => 2025_12_26_183200_change_work_orders_process_type_to_process_id.php} (81%) diff --git a/database/migrations/2025_01_08_100000_add_tenant_id_to_work_order_sub_tables.php b/database/migrations/2025_12_26_100400_add_tenant_id_to_work_order_sub_tables.php similarity index 100% rename from database/migrations/2025_01_08_100000_add_tenant_id_to_work_order_sub_tables.php rename to database/migrations/2025_12_26_100400_add_tenant_id_to_work_order_sub_tables.php diff --git a/database/migrations/2025_01_09_100000_create_work_order_assignees_table.php b/database/migrations/2025_12_26_100600_create_work_order_assignees_table.php similarity index 100% rename from database/migrations/2025_01_09_100000_create_work_order_assignees_table.php rename to database/migrations/2025_12_26_100600_create_work_order_assignees_table.php diff --git a/database/migrations/2025_01_09_100000_change_work_orders_process_type_to_process_id.php b/database/migrations/2025_12_26_183200_change_work_orders_process_type_to_process_id.php similarity index 81% rename from database/migrations/2025_01_09_100000_change_work_orders_process_type_to_process_id.php rename to database/migrations/2025_12_26_183200_change_work_orders_process_type_to_process_id.php index 14ede0c..fbf1593 100644 --- a/database/migrations/2025_01_09_100000_change_work_orders_process_type_to_process_id.php +++ b/database/migrations/2025_12_26_183200_change_work_orders_process_type_to_process_id.php @@ -24,29 +24,43 @@ public function up(): void // 1. 절곡 공정이 없으면 각 테넌트별로 생성 $this->ensureBendingProcessExists(); - // 2. process_id 컬럼 추가 (nullable로 먼저 생성) - Schema::table('work_orders', function (Blueprint $table) { - $table->unsignedBigInteger('process_id') - ->nullable() - ->after('sales_order_id') - ->comment('공정 ID (FK → processes.id)'); - }); + // 2. process_id 컬럼 추가 (이미 존재하면 스킵) + if (!Schema::hasColumn('work_orders', 'process_id')) { + Schema::table('work_orders', function (Blueprint $table) { + $table->unsignedBigInteger('process_id') + ->nullable() + ->after('sales_order_id') + ->comment('공정 ID (FK → processes.id)'); + }); + } // 3. 기존 process_type 데이터를 process_id로 마이그레이션 $this->migrateProcessTypeToProcessId(); - // 4. process_id에 FK 제약 추가 및 NOT NULL로 변경 - Schema::table('work_orders', function (Blueprint $table) { - $table->foreign('process_id') - ->references('id') - ->on('processes') - ->onDelete('restrict'); - }); + // 4. process_id에 FK 제약 추가 (이미 존재하면 스킵) + $hasFk = DB::select(" + SELECT COUNT(*) as cnt FROM information_schema.KEY_COLUMN_USAGE + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 'work_orders' + AND COLUMN_NAME = 'process_id' + AND REFERENCED_TABLE_NAME IS NOT NULL + ")[0]->cnt > 0; - // 5. 기존 process_type 컬럼 제거 - Schema::table('work_orders', function (Blueprint $table) { - $table->dropColumn('process_type'); - }); + if (!$hasFk) { + Schema::table('work_orders', function (Blueprint $table) { + $table->foreign('process_id') + ->references('id') + ->on('processes') + ->onDelete('restrict'); + }); + } + + // 5. 기존 process_type 컬럼 제거 (존재하면 제거) + if (Schema::hasColumn('work_orders', 'process_type')) { + Schema::table('work_orders', function (Blueprint $table) { + $table->dropColumn('process_type'); + }); + } } public function down(): void