From e407c40228c569bb0d55d45983c5a9019f3defbe Mon Sep 17 00:00:00 2001 From: pro Date: Fri, 30 Jan 2026 15:15:09 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=9D=B8=EB=8D=B1=EC=8A=A4=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=EC=B2=B4=ED=81=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sales_scenario_unique 인덱스 삭제 전 존재 여부 확인 - sales_scenario_checkpoint_unique 생성 전 존재 여부 확인 - 서버 환경에서 이미 수동으로 인덱스가 변경된 경우 대응 Co-Authored-By: Claude Opus 4.5 --- ...x_sales_scenario_checklists_unique_key.php | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/database/migrations/2026_01_29_090000_fix_sales_scenario_checklists_unique_key.php b/database/migrations/2026_01_29_090000_fix_sales_scenario_checklists_unique_key.php index fee45fd..75fb113 100644 --- a/database/migrations/2026_01_29_090000_fix_sales_scenario_checklists_unique_key.php +++ b/database/migrations/2026_01_29_090000_fix_sales_scenario_checklists_unique_key.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\DB; return new class extends Migration { @@ -11,19 +12,29 @@ */ public function up(): void { + // 기존 유니크 키가 존재하면 삭제 + $indexes = DB::select("SHOW INDEX FROM sales_scenario_checklists WHERE Key_name = 'sales_scenario_unique'"); + if (count($indexes) > 0) { + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + $table->dropUnique('sales_scenario_unique'); + }); + } + + // checkpoint_index를 nullable로 변경 Schema::table('sales_scenario_checklists', function (Blueprint $table) { - // 기존 유니크 키 삭제 - $table->dropUnique('sales_scenario_unique'); - - // checkpoint_index를 nullable로 변경 $table->unsignedTinyInteger('checkpoint_index')->nullable()->change(); - - // 새 유니크 키 생성 (checkpoint_id 기반) - $table->unique( - ['tenant_id', 'scenario_type', 'step_id', 'checkpoint_id'], - 'sales_scenario_checkpoint_unique' - ); }); + + // 새 유니크 키가 존재하지 않으면 생성 + $newIndexes = DB::select("SHOW INDEX FROM sales_scenario_checklists WHERE Key_name = 'sales_scenario_checkpoint_unique'"); + if (count($newIndexes) === 0) { + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + $table->unique( + ['tenant_id', 'scenario_type', 'step_id', 'checkpoint_id'], + 'sales_scenario_checkpoint_unique' + ); + }); + } } /** @@ -31,18 +42,28 @@ public function up(): void */ public function down(): void { + // 새 유니크 키가 존재하면 삭제 + $indexes = DB::select("SHOW INDEX FROM sales_scenario_checklists WHERE Key_name = 'sales_scenario_checkpoint_unique'"); + if (count($indexes) > 0) { + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + $table->dropUnique('sales_scenario_checkpoint_unique'); + }); + } + + // checkpoint_index를 NOT NULL로 복원 Schema::table('sales_scenario_checklists', function (Blueprint $table) { - // 새 유니크 키 삭제 - $table->dropUnique('sales_scenario_checkpoint_unique'); - - // checkpoint_index를 NOT NULL로 복원 $table->unsignedTinyInteger('checkpoint_index')->nullable(false)->change(); - - // 기존 유니크 키 복원 - $table->unique( - ['tenant_id', 'user_id', 'step_id', 'checkpoint_index'], - 'sales_scenario_unique' - ); }); + + // 기존 유니크 키가 존재하지 않으면 복원 + $oldIndexes = DB::select("SHOW INDEX FROM sales_scenario_checklists WHERE Key_name = 'sales_scenario_unique'"); + if (count($oldIndexes) === 0) { + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + $table->unique( + ['tenant_id', 'user_id', 'step_id', 'checkpoint_index'], + 'sales_scenario_unique' + ); + }); + } } };