refactor: [절곡] code/lot_no 분리 — 코드 체계와 LOT 번호 분리

- bending_items.code: LOT번호(CP260319) → 코드체계(CP)만 저장
- bending_items.lot_no: 기존 code 값 이관 (LOT 번호)
- bending_models.code: 전체코드(GR-KSS01-벽면형-SUS) → 접두사(GR)만 저장
- bending_models.lot_no: 기존 code 값 이관
- unique 제약: code → lot_no로 이동
- BendingCodeService.resolveItem: LIKE → 정확 매칭
- 검색: lot_no 필드 추가
- Swagger 문서 업데이트
This commit is contained in:
2026-03-21 15:06:55 +09:00
parent 78ff01d6b1
commit d6591acdff
8 changed files with 90 additions and 11 deletions

View File

@@ -0,0 +1,70 @@
<?php
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
{
public function up(): void
{
// ── bending_items ──
Schema::table('bending_items', function (Blueprint $table) {
$table->string('lot_no', 50)->nullable()->after('code')->comment('LOT 번호 (기존 code 값 이관)');
});
// 기존 code → lot_no 이관, code에는 앞 2자리(prod+spec)만 남기기
DB::statement("UPDATE bending_items SET lot_no = code, code = LEFT(code, 2) WHERE lot_no IS NULL");
// unique 제약 변경: code → lot_no
Schema::table('bending_items', function (Blueprint $table) {
// 기존 unique 제거
$indexes = collect(DB::select("SHOW INDEX FROM bending_items WHERE Key_name = 'uk_tenant_code'"));
if ($indexes->isNotEmpty()) {
$table->dropUnique('uk_tenant_code');
}
// lot_no에 unique 추가
$table->unique(['tenant_id', 'lot_no', 'deleted_at'], 'uk_tenant_lot_no');
// code 인덱스 유지 (필터용)
$table->index('code', 'idx_bending_code_type');
});
// ── bending_models ──
Schema::table('bending_models', function (Blueprint $table) {
$table->string('lot_no', 100)->nullable()->after('code')->comment('전체 코드 (기존 code 값 이관)');
});
// 기존 code → lot_no 이관, code에는 접두사만 남기기 (GR-, SB-, BB-)
DB::statement("UPDATE bending_models SET lot_no = code, code = CASE
WHEN code LIKE 'GR-%' THEN 'GR'
WHEN code LIKE 'SB-%' THEN 'SB'
WHEN code LIKE 'BB-%' THEN 'BB'
ELSE LEFT(code, 2)
END WHERE lot_no IS NULL");
}
public function down(): void
{
// bending_items: lot_no → code 복원
DB::statement("UPDATE bending_items SET code = lot_no WHERE lot_no IS NOT NULL");
Schema::table('bending_items', function (Blueprint $table) {
$indexes = collect(DB::select("SHOW INDEX FROM bending_items WHERE Key_name = 'uk_tenant_lot_no'"));
if ($indexes->isNotEmpty()) {
$table->dropUnique('uk_tenant_lot_no');
}
$indexes2 = collect(DB::select("SHOW INDEX FROM bending_items WHERE Key_name = 'idx_bending_code_type'"));
if ($indexes2->isNotEmpty()) {
$table->dropIndex('idx_bending_code_type');
}
$table->unique(['tenant_id', 'code', 'deleted_at'], 'uk_tenant_code');
$table->dropColumn('lot_no');
});
// bending_models: lot_no → code 복원
DB::statement("UPDATE bending_models SET code = lot_no WHERE lot_no IS NOT NULL");
Schema::table('bending_models', function (Blueprint $table) {
$table->dropColumn('lot_no');
});
}
};