From 9f872cb51c8c0c6e23feb468a12829ffd9272e27 Mon Sep 17 00:00:00 2001 From: pro Date: Fri, 30 Jan 2026 15:19:02 +0900 Subject: [PATCH] =?UTF-8?q?docs:=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=88=98=EC=A0=95=20=EC=9D=B4=EB=A0=A5=20?= =?UTF-8?q?=EB=B0=8F=20Laravel=2012=20=EA=B0=80=EC=9D=B4=EB=93=9C=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 - 서버 호환성 문제 해결 내역 - Laravel 12 마이그레이션 작성 가이드 Co-Authored-By: Claude Opus 4.5 --- 서버작업이력.md | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/서버작업이력.md b/서버작업이력.md index 5b0a65f2..b03019b2 100644 --- a/서버작업이력.md +++ b/서버작업이력.md @@ -265,6 +265,105 @@ ### 10. sales_scenario_checklists 테이블 스키마 동기화 --- +### 11. 마이그레이션 파일 수정 (서버 호환성) + +**문제**: 서버에서 git push 후 자동 마이그레이션 실행 시 여러 오류 발생 + +**수정된 마이그레이션 파일들**: + +#### 1) `2026_01_29_090000_fix_sales_scenario_checklists_unique_key.php` +- **오류**: `Can't DROP 'sales_scenario_unique'; check that column/key exists` +- **원인**: 서버에 해당 인덱스가 없음 (이미 수동으로 다른 이름으로 생성됨) +- **해결**: 인덱스 삭제/생성 전 `SHOW INDEX` 쿼리로 존재 여부 확인 + +```php +// 수정 전 +$table->dropUnique('sales_scenario_unique'); + +// 수정 후 +$indexes = DB::select("SHOW INDEX FROM sales_scenario_checklists WHERE Key_name = 'sales_scenario_unique'"); +if (count($indexes) > 0) { + $table->dropUnique('sales_scenario_unique'); +} +``` + +#### 2) `2026_01_29_093000_add_gcs_uri_to_sales_consultations.php` +- **오류**: `Table 'sam.sales_consultations' doesn't exist` +- **원인**: 테이블 생성 마이그레이션보다 먼저 실행됨 +- **해결**: `Schema::hasTable()` 체크 추가 + +```php +public function up(): void +{ + if (!Schema::hasTable('sales_consultations')) { + return; + } + // ... 기존 로직 +} +``` + +#### 3) `2026_01_29_100200_create_sales_scenario_checklists_table.php` +- **오류**: `Table 'sales_scenario_checklists' already exists` +- **원인**: 서버에 이미 테이블이 존재 (수동 생성됨) +- **해결**: `Schema::hasTable()` 체크 추가 + +```php +public function up(): void +{ + if (Schema::hasTable('sales_scenario_checklists')) { + return; + } + Schema::create('sales_scenario_checklists', function (Blueprint $table) { + // ... + }); +} +``` + +#### 4) `2026_01_30_150000_add_missing_columns_to_sales_scenario_checklists_table.php` +- **오류**: `Method getDoctrineSchemaManager does not exist` +- **원인**: Laravel 12에서 Doctrine DBAL 제거됨 +- **해결**: `DB::select("SHOW INDEX ...")` 쿼리로 대체 + +```php +// 수정 전 (Laravel 11 이하) +$sm = Schema::getConnection()->getDoctrineSchemaManager(); +$indexes = $sm->listTableIndexes('sales_scenario_checklists'); + +// 수정 후 (Laravel 12 호환) +$uniqueExists = DB::select("SHOW INDEX FROM sales_scenario_checklists WHERE Key_name = 'sales_scenario_checkpoint_unique'"); +if (empty($uniqueExists)) { + // 인덱스 추가 +} +``` + +--- + +## 참고: 마이그레이션 작성 가이드 (Laravel 12) + +### 안전한 마이그레이션 패턴 + +```php +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; + +// 1. 테이블 존재 여부 확인 +if (Schema::hasTable('table_name')) { ... } + +// 2. 컬럼 존재 여부 확인 +if (Schema::hasColumn('table_name', 'column_name')) { ... } + +// 3. 인덱스 존재 여부 확인 (Laravel 12) +$indexes = DB::select("SHOW INDEX FROM table_name WHERE Key_name = 'index_name'"); +if (empty($indexes)) { ... } +``` + +### 주의사항 +- Laravel 12에서 `getDoctrineSchemaManager()` 사용 불가 +- 테이블/컬럼 생성 전 항상 존재 여부 체크 +- 인덱스 삭제 전 항상 존재 여부 체크 + +--- + ## 참고: Docker vs 서버 경로 차이 | 항목 | Docker (로컬) | 서버 |