feat : common_codes 테이블 수정

This commit is contained in:
2025-07-23 16:14:18 +09:00
parent 609ac39ffb
commit 593d81c4cb
2 changed files with 58 additions and 3 deletions

View File

@@ -8,12 +8,35 @@
class CommonCode extends Model
{
use SoftDeletes;
protected $fillable = ['tenant_id','code_group','code','name','parent_id','description','is_active','sort_order'];
public function parent() {
protected $table = 'common_codes';
protected $fillable = [
'tenant_id',
'code_group',
'code',
'name',
'parent_id',
'attributes',
'description',
'is_active',
'sort_order'
];
protected $casts = [
'attributes' => 'array',
'is_active' => 'boolean',
];
// 관계: 상위 코드
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children() {
// 관계: 하위 코드들
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}
}

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('common_codes', function (Blueprint $table) {
// 1. attributes 컬럼 추가
if (!Schema::hasColumn('common_codes', 'attributes')) {
$table->json('attributes')->nullable()->comment('동적 속성')->after('parent_id');
}
// 2. is_active 타입 및 코멘트 변경
$table->tinyInteger('is_active')->default(1)->comment('사용여부')->change();
});
// 3. 테이블 코멘트
DB::statement("ALTER TABLE `common_codes` COMMENT = '공통코드 트리';");
}
public function down(): void
{
Schema::table('common_codes', function (Blueprint $table) {
if (Schema::hasColumn('common_codes', 'attributes')) {
$table->dropColumn('attributes');
}
});
}
};