fix: Items 이관 마이그레이션 비활성화

- 데이터 이관 로직 임시 비활성화
- item_type 컬럼 길이 문제로 정책 정리 후 재작업 예정
This commit is contained in:
2025-12-12 09:54:56 +09:00
parent 33260d5333
commit b6bea99cd9
3 changed files with 72 additions and 103 deletions

View File

@@ -1,120 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
/**
* Products/Materials 데이터를 Items 테이블로 이관
*
* 1. Products 테이블 데이터 → Items 이관
* 2. Materials 테이블 데이터 → Items 이관
* 3. ID 매핑 테이블 생성
* ⚠️ 이 마이그레이션은 비활성화됨
* - items 테이블 정책 정리 후 재작업 예정
* - 2025_12_12_100000_rollback_items_migration.php 참조
*/
return new class extends Migration
{
public function up(): void
{
// 1. Products → Items 이관
echo "Products 데이터 이관 시작...\n";
$productsBefore = DB::table('products')->count();
echo "- Products 원본: {$productsBefore}\n";
DB::statement("
INSERT INTO items (
tenant_id, item_type, code, name, unit, category_id,
description, attributes, attributes_archive, options, bom,
is_sellable, is_purchasable, is_producible,
safety_stock, lead_time, is_variable_size, product_category, part_type,
bending_diagram, bending_details, specification_file, specification_file_name,
certification_file, certification_file_name, certification_number,
certification_start_date, certification_end_date,
is_active, created_by, updated_by, deleted_by,
created_at, updated_at, deleted_at,
legacy_table, legacy_id
)
SELECT
tenant_id, product_type, code, name, unit, category_id,
description, attributes, attributes_archive, options, bom,
is_sellable, is_purchasable, is_producible,
safety_stock, lead_time, is_variable_size, product_category, part_type,
bending_diagram, bending_details, specification_file, specification_file_name,
certification_file, certification_file_name, certification_number,
certification_start_date, certification_end_date,
is_active, created_by, updated_by, deleted_by,
created_at, updated_at, deleted_at,
'products', id
FROM products
");
$productsAfter = DB::table('items')->where('legacy_table', 'products')->count();
echo "- Items로 이관: {$productsAfter}\n";
// 2. Materials → Items 이관
echo "\nMaterials 데이터 이관 시작...\n";
$materialsBefore = DB::table('materials')->count();
echo "- Materials 원본: {$materialsBefore}\n";
DB::statement("
INSERT INTO items (
tenant_id, item_type, code, name, unit, category_id,
specification, attributes, options,
item_name, is_inspection, search_tag, remarks,
is_active, created_by, updated_by, deleted_by,
created_at, updated_at, deleted_at,
legacy_table, legacy_id
)
SELECT
tenant_id, material_type, material_code, name, unit, category_id,
specification, attributes, options,
item_name, is_inspection, search_tag, remarks,
is_active, created_by, updated_by, deleted_by,
created_at, updated_at, deleted_at,
'materials', id
FROM materials
");
$materialsAfter = DB::table('items')->where('legacy_table', 'materials')->count();
echo "- Items로 이관: {$materialsAfter}\n";
// 3. ID 매핑 테이블 생성
echo "\nID 매핑 테이블 생성 시작...\n";
DB::statement("
INSERT INTO item_id_mappings (new_item_id, legacy_table, legacy_id)
SELECT id, legacy_table, legacy_id
FROM items
WHERE legacy_table IS NOT NULL AND legacy_id IS NOT NULL
");
$mappingsCount = DB::table('item_id_mappings')->count();
echo "- ID 매핑: {$mappingsCount}건 생성\n";
// 4. 검증
echo "\n=== 이관 검증 ===\n";
$totalItems = DB::table('items')->count();
$totalOriginal = $productsBefore + $materialsBefore;
echo "- 원본 합계: {$totalOriginal}건 (Products: {$productsBefore} + Materials: {$materialsBefore})\n";
echo "- Items 합계: {$totalItems}\n";
if ($totalItems === $totalOriginal) {
echo "✅ 데이터 이관 성공!\n";
} else {
echo "⚠️ 데이터 불일치! 확인 필요\n";
}
// 비활성화: 정책 정리 후 재작업 예정
echo "⚠️ 이 마이그레이션은 비활성화되었습니다. 정책 정리 후 재작업 예정.\n";
}
public function down(): void
{
// 롤백: Items 테이블 데이터 삭제 (매핑 테이블은 CASCADE로 자동 삭제)
echo "Items 데이터 롤백 시작...\n";
$countBefore = DB::table('items')->count();
DB::table('items')->truncate();
$countAfter = DB::table('items')->count();
echo "- 삭제된 Items: {$countBefore}\n";
echo "- 롤백 완료\n";
// 비활성화
}
};