fix : 공통으로 파일관리 - Polymorphic 구조로 수정

This commit is contained in:
2025-07-24 18:08:24 +09:00
parent 84173d9afb
commit 19839323ae

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('files', function (Blueprint $table) {
// 기존 컬럼 제거 (target_table, target_id)
$table->dropColumn(['target_table', 'target_id']);
// Polymorphic 컬럼 추가
$table->unsignedBigInteger('fileable_id')->after('description')->comment('Polymorphic - 연결된 모델의 PK');
$table->string('fileable_type', 100)->after('fileable_id')->comment('Polymorphic - 연결된 모델 클래스명');
});
}
public function down(): void
{
Schema::table('files', function (Blueprint $table) {
// Polymorphic 컬럼 제거
$table->dropColumn(['fileable_id', 'fileable_type']);
// 다시 기존 방식으로 복원
$table->string('target_table', 50)->after('description')->comment('연결된 테이블명');
$table->unsignedBigInteger('target_id')->after('target_table')->comment('연결된 테이블의 PK ID');
});
}
};