## 주요 변경사항
### 1. 시스템 필드 정의 DB 마이그레이션
- 기존 하드코딩된 Constants/SystemFieldDefinitions.php 제거
- 신규 Models/SystemFieldDefinition.php 모델 추가
- system_field_definitions 테이블 기반 동적 관리
### 2. 테이블 등록 시 자동 필드 생성
- DB 실제 테이블 목록에서 선택하여 등록
- MySQL INFORMATION_SCHEMA에서 컬럼 정보 자동 조회
- COLUMN_COMMENT를 필드명(한글)으로 사용
- IS_NULLABLE로 필수 여부 자동 설정
- 시스템 컬럼(id, tenant_id, timestamps 등) 자동 제외
### 3. 필드명 동기화 기능
- 기존 등록된 테이블의 필드명을 DB COMMENT로 업데이트
- POST /source-tables/{table}/sync-field-names API 추가
### 4. 시딩 상태 계산 수정
- getFieldCountFor(): is_seed_default=true인 필드만 카운트
- getTotalFieldCountFor(): 전체 활성 필드 카운트 (신규)
- "제외" 필드가 있어도 시딩 완료 상태 정상 표시
### 5. UI 개선
- 시스템 필드 정의 탭에서 테이블별 관리
- 테이블 헤더에 "필드명 동기화", "삭제" 버튼 추가
- 테이블 선택 모달에서 COMMENT(한글명) 표시
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
141 lines
3.9 KiB
PHP
141 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* 시스템 필드 정의 모델
|
|
*
|
|
* 각 소스 테이블(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',
|
|
];
|
|
|
|
/**
|
|
* 소스 테이블 목록 조회 (라벨 포함)
|
|
* - 등록된 모든 테이블 포함 (_meta_ 플레이스홀더 포함)
|
|
*/
|
|
public static function getSourceTables(): Collection
|
|
{
|
|
return self::query()
|
|
->select('source_table', 'source_table_label')
|
|
->groupBy('source_table', 'source_table_label')
|
|
->orderBy('source_table')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 소스 테이블 목록 (key => label 형태)
|
|
* - 등록된 모든 테이블 포함 (드롭다운용)
|
|
*/
|
|
public static function getSourceTableOptions(): array
|
|
{
|
|
return self::getSourceTables()
|
|
->pluck('source_table_label', 'source_table')
|
|
->toArray();
|
|
}
|
|
|
|
/**
|
|
* 활성 필드가 있는 소스 테이블 목록 조회
|
|
* - 시딩 상태 조회 등에서 사용
|
|
*/
|
|
public static function getActiveSourceTables(): 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();
|
|
}
|
|
|
|
/**
|
|
* 특정 소스 테이블의 기본 시딩 대상 필드 수 조회
|
|
* - 시딩 상태 비교용 (is_seed_default=true인 필드만 카운트)
|
|
*/
|
|
public static function getFieldCountFor(string $sourceTable): int
|
|
{
|
|
return self::query()
|
|
->where('source_table', $sourceTable)
|
|
->where('is_active', true)
|
|
->where('is_seed_default', true)
|
|
->count();
|
|
}
|
|
|
|
/**
|
|
* 특정 소스 테이블의 전체 필드 수 조회
|
|
* - 제외된 필드 포함 전체 카운트
|
|
*/
|
|
public static function getTotalFieldCountFor(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();
|
|
}
|
|
}
|