From 18ef35a8735eafcf65f1a3116b3710485cf3fed6 Mon Sep 17 00:00:00 2001 From: kent Date: Sun, 14 Dec 2025 01:25:43 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=A0=88=EA=B1=B0=EC=8B=9C=20produ?= =?UTF-8?q?ct=5Fid/material=5Fid=20=EC=BB=AC=EB=9F=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - orders.product_id 삭제 - order_items.product_id 삭제 - quotes.product_id 삭제 - material_receipts.material_id 삭제 - lots.material_id 삭제 items 테이블 통합 완료로 더 이상 불필요한 컬럼 정리 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- ...rop_legacy_product_material_id_columns.php | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 database/migrations/2025_12_14_012415_drop_legacy_product_material_id_columns.php diff --git a/database/migrations/2025_12_14_012415_drop_legacy_product_material_id_columns.php b/database/migrations/2025_12_14_012415_drop_legacy_product_material_id_columns.php new file mode 100644 index 0000000..79a8ade --- /dev/null +++ b/database/migrations/2025_12_14_012415_drop_legacy_product_material_id_columns.php @@ -0,0 +1,111 @@ +dropColumn('product_id'); + }); + } + + // 2. order_items.product_id 삭제 + if (Schema::hasTable('order_items') && Schema::hasColumn('order_items', 'product_id')) { + Schema::table('order_items', function (Blueprint $table) { + $table->dropColumn('product_id'); + }); + } + + // 3. quotes.product_id 삭제 + if (Schema::hasTable('quotes') && Schema::hasColumn('quotes', 'product_id')) { + Schema::table('quotes', function (Blueprint $table) { + $table->dropColumn('product_id'); + }); + } + + // 4. material_receipts.material_id 삭제 + if (Schema::hasTable('material_receipts') && Schema::hasColumn('material_receipts', 'material_id')) { + Schema::table('material_receipts', function (Blueprint $table) { + $table->dropColumn('material_id'); + }); + } + + // 5. lots.material_id 삭제 + if (Schema::hasTable('lots') && Schema::hasColumn('lots', 'material_id')) { + Schema::table('lots', function (Blueprint $table) { + $table->dropColumn('material_id'); + }); + } + + DB::statement("SELECT 'Dropped legacy product_id/material_id columns' AS result"); + } + + /** + * Reverse the migrations. + * + * 주의: 컬럼 복원만 수행, 데이터는 item_id_mappings로 복원 필요 + */ + public function down(): void + { + // 1. orders.product_id 복원 + if (Schema::hasTable('orders') && ! Schema::hasColumn('orders', 'product_id')) { + Schema::table('orders', function (Blueprint $table) { + $table->unsignedBigInteger('product_id')->nullable()->after('category_code') + ->comment('(deprecated) 기존 products 참조'); + }); + } + + // 2. order_items.product_id 복원 + if (Schema::hasTable('order_items') && ! Schema::hasColumn('order_items', 'product_id')) { + Schema::table('order_items', function (Blueprint $table) { + $table->unsignedBigInteger('product_id')->nullable()->after('serial_no') + ->comment('(deprecated) 기존 products 참조'); + }); + } + + // 3. quotes.product_id 복원 + if (Schema::hasTable('quotes') && ! Schema::hasColumn('quotes', 'product_id')) { + Schema::table('quotes', function (Blueprint $table) { + $table->unsignedBigInteger('product_id')->nullable()->after('product_category') + ->comment('(deprecated) 기존 products 참조'); + }); + } + + // 4. material_receipts.material_id 복원 + if (Schema::hasTable('material_receipts') && ! Schema::hasColumn('material_receipts', 'material_id')) { + Schema::table('material_receipts', function (Blueprint $table) { + $table->unsignedBigInteger('material_id')->nullable()->first() + ->comment('(deprecated) 기존 materials 참조'); + }); + } + + // 5. lots.material_id 복원 + if (Schema::hasTable('lots') && ! Schema::hasColumn('lots', 'material_id')) { + Schema::table('lots', function (Blueprint $table) { + $table->unsignedBigInteger('material_id')->nullable()->after('id') + ->comment('(deprecated) 기존 materials 참조'); + }); + } + + // 데이터 복원 안내 + DB::statement("SELECT 'Columns restored. Use item_id_mappings to restore data if needed.' AS warning"); + } +};