diff --git a/database/migrations/2026_01_30_150000_add_missing_columns_to_sales_scenario_checklists_table.php b/database/migrations/2026_01_30_150000_add_missing_columns_to_sales_scenario_checklists_table.php new file mode 100644 index 0000000..fd081f3 --- /dev/null +++ b/database/migrations/2026_01_30_150000_add_missing_columns_to_sales_scenario_checklists_table.php @@ -0,0 +1,107 @@ +enum('scenario_type', ['sales', 'manager']) + ->default('sales') + ->comment('시나리오 유형') + ->after('tenant_id'); + } + }); + + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + // checkpoint_id 컬럼 추가 (step_id 다음에) + if (!Schema::hasColumn('sales_scenario_checklists', 'checkpoint_id')) { + $table->string('checkpoint_id', 50) + ->nullable() + ->comment('체크포인트 ID') + ->after('step_id'); + } + }); + + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + // checked_at 컬럼 추가 (is_checked 다음에) + if (!Schema::hasColumn('sales_scenario_checklists', 'checked_at')) { + $table->timestamp('checked_at') + ->nullable() + ->comment('체크 일시') + ->after('is_checked'); + } + }); + + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + // checked_by 컬럼 추가 (checked_at 다음에) + if (!Schema::hasColumn('sales_scenario_checklists', 'checked_by')) { + $table->unsignedBigInteger('checked_by') + ->nullable() + ->comment('체크한 사용자 ID') + ->after('checked_at'); + } + }); + + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + // memo 컬럼 추가 (checked_by 다음에) + if (!Schema::hasColumn('sales_scenario_checklists', 'memo')) { + $table->text('memo') + ->nullable() + ->comment('메모') + ->after('checked_by'); + } + }); + + // 인덱스 추가 (이미 존재하면 무시) + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + $sm = Schema::getConnection()->getDoctrineSchemaManager(); + $indexes = $sm->listTableIndexes('sales_scenario_checklists'); + + // UNIQUE KEY 추가 + if (!isset($indexes['sales_scenario_checkpoint_unique'])) { + $table->unique( + ['tenant_id', 'scenario_type', 'step_id', 'checkpoint_id'], + 'sales_scenario_checkpoint_unique' + ); + } + + // INDEX 추가 + if (!isset($indexes['sales_scenario_checklists_tenant_id_scenario_type_index'])) { + $table->index( + ['tenant_id', 'scenario_type'], + 'sales_scenario_checklists_tenant_id_scenario_type_index' + ); + } + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('sales_scenario_checklists', function (Blueprint $table) { + // 인덱스 삭제 + $table->dropIndex('sales_scenario_checklists_tenant_id_scenario_type_index'); + $table->dropUnique('sales_scenario_checkpoint_unique'); + + // 컬럼 삭제 + $table->dropColumn([ + 'scenario_type', + 'checkpoint_id', + 'checked_at', + 'checked_by', + 'memo', + ]); + }); + } +};