From 964ee40e8d50456f98864ee7674ca67a944765f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Thu, 12 Mar 2026 11:00:15 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[equipment]=20=EA=B8=B0=EB=B3=B8=20DB?= =?UTF-8?q?=EC=97=90=20equipment=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 마이그레이션이 codebridge DB에만 테이블을 생성하는 문제 수정 - 운영서버(API+React)에서는 기본 DB(sam/sam_prod)에 테이블 필요 - hasTable() 체크로 이미 존재하는 환경에서는 건너뜀 - 모든 컬럼 최신 스키마 반영 (inspection_cycle, sub_manager_id, options) - options 마이그레이션도 hasTable/hasColumn 안전 체크 추가 --- ...2_100001_ensure_equipment_tables_exist.php | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 database/migrations/2026_03_12_100001_ensure_equipment_tables_exist.php diff --git a/database/migrations/2026_03_12_100001_ensure_equipment_tables_exist.php b/database/migrations/2026_03_12_100001_ensure_equipment_tables_exist.php new file mode 100644 index 0000000..1bcc97e --- /dev/null +++ b/database/migrations/2026_03_12_100001_ensure_equipment_tables_exist.php @@ -0,0 +1,203 @@ +id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->string('equipment_code', 20)->comment('설비코드 (KD-M-001 형식)'); + $table->string('name', 100)->comment('설비명'); + $table->string('equipment_type', 50)->nullable()->comment('설비유형'); + $table->string('specification', 255)->nullable()->comment('규격'); + $table->string('manufacturer', 100)->nullable()->comment('제조사'); + $table->string('model_name', 100)->nullable()->comment('모델명'); + $table->string('serial_no', 100)->nullable()->comment('제조번호'); + $table->string('location', 100)->nullable()->comment('위치'); + $table->string('production_line', 50)->nullable()->comment('생산라인'); + $table->date('purchase_date')->nullable()->comment('구입일'); + $table->date('install_date')->nullable()->comment('설치일'); + $table->decimal('purchase_price', 15, 2)->nullable()->comment('구입가격'); + $table->integer('useful_life')->nullable()->comment('내용연수'); + $table->string('status', 20)->default('active')->comment('상태: active/idle/disposed'); + $table->date('disposed_date')->nullable()->comment('폐기일'); + $table->foreignId('manager_id')->nullable()->comment('담당자 ID'); + $table->foreignId('sub_manager_id')->nullable()->comment('부 담당자 ID'); + $table->string('photo_path', 500)->nullable()->comment('설비사진 경로'); + $table->text('memo')->nullable()->comment('비고'); + $table->json('options')->nullable()->comment('확장 속성 JSON'); + $table->tinyInteger('is_active')->default(1)->comment('사용여부'); + $table->integer('sort_order')->default(0)->comment('정렬순서'); + $table->foreignId('created_by')->nullable()->comment('생성자 ID'); + $table->foreignId('updated_by')->nullable()->comment('수정자 ID'); + $table->foreignId('deleted_by')->nullable()->comment('삭제자 ID'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['tenant_id', 'equipment_code'], 'uq_equipment_code'); + $table->index(['tenant_id', 'status'], 'idx_equipment_status'); + $table->index(['tenant_id', 'production_line'], 'idx_equipment_line'); + $table->index(['tenant_id', 'equipment_type'], 'idx_equipment_type'); + }); + } + + // 2. equipment_inspection_templates (점검항목 템플릿) + if (! Schema::hasTable('equipment_inspection_templates')) { + Schema::create('equipment_inspection_templates', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->unsignedBigInteger('equipment_id')->comment('설비 ID'); + $table->string('inspection_cycle', 20)->default('daily') + ->comment('점검주기: daily/weekly/monthly/bimonthly/quarterly/semiannual'); + $table->integer('item_no')->comment('항목번호'); + $table->string('check_point', 50)->comment('점검개소'); + $table->string('check_item', 100)->comment('점검항목'); + $table->string('check_timing', 20)->nullable()->comment('시기: operating/stopped'); + $table->string('check_frequency', 50)->nullable()->comment('주기'); + $table->text('check_method')->nullable()->comment('점검방법 및 기준'); + $table->integer('sort_order')->default(0)->comment('정렬순서'); + $table->tinyInteger('is_active')->default(1)->comment('사용여부'); + $table->timestamps(); + + $table->unique(['equipment_id', 'inspection_cycle', 'item_no'], 'uq_equipment_cycle_item_no'); + $table->index('tenant_id', 'idx_insp_tmpl_tenant'); + $table->index('inspection_cycle', 'idx_insp_tmpl_cycle'); + + $table->foreign('equipment_id') + ->references('id') + ->on('equipments') + ->onDelete('cascade'); + }); + } + + // 3. equipment_inspections (점검 헤더) + if (! Schema::hasTable('equipment_inspections')) { + Schema::create('equipment_inspections', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->unsignedBigInteger('equipment_id')->comment('설비 ID'); + $table->string('inspection_cycle', 20)->default('daily') + ->comment('점검주기: daily/weekly/monthly/bimonthly/quarterly/semiannual'); + $table->string('year_month', 7)->comment('점검년월 (2026-02)'); + $table->string('overall_judgment', 10)->nullable()->comment('종합판정: OK/NG'); + $table->foreignId('inspector_id')->nullable()->comment('점검자 ID'); + $table->text('repair_note')->nullable()->comment('수리내역'); + $table->text('issue_note')->nullable()->comment('이상내용'); + $table->foreignId('created_by')->nullable()->comment('생성자 ID'); + $table->foreignId('updated_by')->nullable()->comment('수정자 ID'); + $table->timestamps(); + + $table->unique(['tenant_id', 'equipment_id', 'inspection_cycle', 'year_month'], 'uq_inspection_cycle_period'); + $table->index(['tenant_id', 'inspection_cycle', 'year_month'], 'idx_inspection_cycle_period'); + + $table->foreign('equipment_id') + ->references('id') + ->on('equipments') + ->onDelete('cascade'); + }); + } + + // 4. equipment_inspection_details (점검 상세) + if (! Schema::hasTable('equipment_inspection_details')) { + Schema::create('equipment_inspection_details', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('inspection_id')->comment('점검 헤더 ID'); + $table->unsignedBigInteger('template_item_id')->comment('점검항목 템플릿 ID'); + $table->date('check_date')->comment('점검일'); + $table->string('result', 10)->nullable()->comment('결과: good/bad/repaired'); + $table->string('note', 500)->nullable()->comment('비고'); + $table->timestamps(); + + $table->unique(['inspection_id', 'template_item_id', 'check_date'], 'uq_inspection_detail'); + + $table->foreign('inspection_id') + ->references('id') + ->on('equipment_inspections') + ->onDelete('cascade'); + + $table->foreign('template_item_id') + ->references('id') + ->on('equipment_inspection_templates') + ->onDelete('cascade'); + }); + } + + // 5. equipment_repairs (수리이력) + if (! Schema::hasTable('equipment_repairs')) { + Schema::create('equipment_repairs', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->unsignedBigInteger('equipment_id')->comment('설비 ID'); + $table->date('repair_date')->comment('수리일'); + $table->string('repair_type', 20)->comment('보전구분: internal/external'); + $table->decimal('repair_hours', 5, 1)->nullable()->comment('수리시간'); + $table->text('description')->nullable()->comment('수리내용'); + $table->decimal('cost', 15, 2)->nullable()->comment('수리비용'); + $table->string('vendor', 100)->nullable()->comment('외주업체'); + $table->foreignId('repaired_by')->nullable()->comment('수리자 ID'); + $table->text('memo')->nullable()->comment('비고'); + $table->json('options')->nullable()->comment('확장 속성 JSON'); + $table->foreignId('created_by')->nullable()->comment('생성자 ID'); + $table->foreignId('updated_by')->nullable()->comment('수정자 ID'); + $table->timestamps(); + $table->softDeletes(); + + $table->index(['tenant_id', 'repair_date'], 'idx_repair_date'); + $table->index(['tenant_id', 'equipment_id'], 'idx_repair_equipment'); + + $table->foreign('equipment_id') + ->references('id') + ->on('equipments') + ->onDelete('cascade'); + }); + } + + // 6. equipment_process (설비-공정 매핑) + if (! Schema::hasTable('equipment_process')) { + Schema::create('equipment_process', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('equipment_id')->comment('설비 ID'); + $table->unsignedBigInteger('process_id')->comment('공정 ID'); + $table->tinyInteger('is_primary')->default(0)->comment('주 설비 여부'); + $table->timestamps(); + + $table->unique(['equipment_id', 'process_id'], 'uq_equipment_process'); + + $table->foreign('equipment_id') + ->references('id') + ->on('equipments') + ->onDelete('cascade'); + + $table->foreign('process_id') + ->references('id') + ->on('processes') + ->onDelete('cascade'); + }); + } + } + + public function down(): void + { + // 역순으로 삭제 (FK 의존성) + Schema::dropIfExists('equipment_process'); + Schema::dropIfExists('equipment_inspection_details'); + Schema::dropIfExists('equipment_repairs'); + Schema::dropIfExists('equipment_inspections'); + Schema::dropIfExists('equipment_inspection_templates'); + Schema::dropIfExists('equipments'); + } +};