feat: SystemFieldDefinition 시스템 필드 정의 기능 추가
- SystemFieldDefinition 모델 추가 (items/tenants/users 필드 정의) - SystemFieldDefinitionSeeder 추가 - source_table 단독 인덱스 추가 (쿼리 성능 향상) - LOGICAL_RELATIONSHIPS.md 자동 생성 문서 업데이트 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
101
app/Models/SystemFieldDefinition.php
Normal file
101
app/Models/SystemFieldDefinition.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* 시스템 필드 정의 모델
|
||||
*
|
||||
* 각 소스 테이블(items, tenants, users)의 시스템 필드를 정의합니다.
|
||||
* 테넌트별 item_fields 시딩 시 참조하는 마스터 데이터입니다.
|
||||
*/
|
||||
class SystemFieldDefinition extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'source_table',
|
||||
'source_table_label',
|
||||
'field_key',
|
||||
'field_name',
|
||||
'field_type',
|
||||
'order_no',
|
||||
'is_required',
|
||||
'is_seed_default',
|
||||
'default_value',
|
||||
'options',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'order_no' => 'integer',
|
||||
'is_required' => 'boolean',
|
||||
'is_seed_default' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'options' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* 소스 테이블 목록 조회
|
||||
*/
|
||||
public static function getSourceTables(): Collection
|
||||
{
|
||||
return self::query()
|
||||
->select('source_table', 'source_table_label')
|
||||
->where('is_active', true)
|
||||
->groupBy('source_table', 'source_table_label')
|
||||
->orderBy('source_table')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 소스 테이블의 필드 목록 조회
|
||||
*/
|
||||
public static function getFieldsFor(string $sourceTable, bool $onlyActive = true): Collection
|
||||
{
|
||||
$query = self::query()
|
||||
->where('source_table', $sourceTable)
|
||||
->orderBy('order_no');
|
||||
|
||||
if ($onlyActive) {
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 소스 테이블의 기본 시딩 대상 필드 목록 조회
|
||||
*/
|
||||
public static function getSeedDefaultFieldsFor(string $sourceTable): Collection
|
||||
{
|
||||
return self::query()
|
||||
->where('source_table', $sourceTable)
|
||||
->where('is_active', true)
|
||||
->where('is_seed_default', true)
|
||||
->orderBy('order_no')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 소스 테이블의 필드 수 조회
|
||||
*/
|
||||
public static function getFieldCountFor(string $sourceTable): int
|
||||
{
|
||||
return self::query()
|
||||
->where('source_table', $sourceTable)
|
||||
->where('is_active', true)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 소스 테이블의 시스템 필드 키 목록
|
||||
*/
|
||||
public static function getAllSystemFieldKeys(string $sourceTable): array
|
||||
{
|
||||
return self::query()
|
||||
->where('source_table', $sourceTable)
|
||||
->pluck('field_key')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user