Files
sam-api/database/migrations/2025_12_12_100000_rollback_items_migration.php

49 lines
1.6 KiB
PHP
Raw Normal View History

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Items 테이블 이관 롤백
*
* 이전 마이그레이션(2025_12_11_220200)에서 이관된 데이터를 정리하고
* items, item_id_mappings 테이블을 삭제합니다.
*
* 추후 items 테이블 정책 정리 재작업 예정
*/
return new class extends Migration
{
public function up(): void
{
// FK 제약 조건 비활성화
DB::statement('SET FOREIGN_KEY_CHECKS=0');
// 1. item_id_mappings 테이블 먼저 삭제 (FK 참조)
if (Schema::hasTable('item_id_mappings')) {
$mappingsCount = DB::table('item_id_mappings')->count();
echo "item_id_mappings 테이블 삭제: {$mappingsCount}\n";
Schema::dropIfExists('item_id_mappings');
}
// 2. items 테이블 삭제
if (Schema::hasTable('items')) {
$itemsCount = DB::table('items')->count();
echo "items 테이블 삭제: {$itemsCount}\n";
Schema::dropIfExists('items');
}
// FK 제약 조건 재활성화
DB::statement('SET FOREIGN_KEY_CHECKS=1');
echo "✅ Items 관련 테이블 롤백 완료\n";
}
public function down(): void
{
// 롤백 시 아무 작업도 하지 않음
// items 테이블은 재설계 후 새로운 마이그레이션으로 생성 예정
echo "⚠️ 이 마이그레이션은 롤백되지 않습니다. items 테이블 재설계 후 새로운 마이그레이션을 사용하세요.\n";
}
};