87 lines
3.5 KiB
Markdown
87 lines
3.5 KiB
Markdown
|
|
# 논리적 데이터베이스 관계 문서 (간소화)
|
||
|
|
|
||
|
|
> **생성일**: 2025-09-24 22:15:54
|
||
|
|
> **소스**: 알려진 비즈니스 관계 기반
|
||
|
|
> **참고**: FK 제거 후 논리적 관계 명세
|
||
|
|
|
||
|
|
## 📊 테이블별 논리적 관계
|
||
|
|
|
||
|
|
### 📋 `users` - 사용자 계정
|
||
|
|
|
||
|
|
- **user_tenants (hasMany)**: `user_tenants.user_id → users.id`
|
||
|
|
- **user_roles (hasMany)**: `user_roles.user_id → users.id`
|
||
|
|
- **audit_logs (hasMany)**: `audit_logs.actor_id → users.id (생성자)`
|
||
|
|
|
||
|
|
### 📋 `tenants` - 테넌트 (회사/조직)
|
||
|
|
|
||
|
|
- **user_tenants (hasMany)**: `user_tenants.tenant_id → tenants.id`
|
||
|
|
- **classifications (hasMany)**: `classifications.tenant_id → tenants.id (논리적)`
|
||
|
|
- **departments (hasMany)**: `departments.tenant_id → tenants.id`
|
||
|
|
- **products (hasMany)**: `products.tenant_id → tenants.id`
|
||
|
|
- **orders (hasMany)**: `orders.tenant_id → tenants.id`
|
||
|
|
|
||
|
|
### 📋 `categories` - 제품 카테고리 (계층구조)
|
||
|
|
|
||
|
|
- **parent (belongsTo)**: `categories.parent_id → categories.id`
|
||
|
|
- **children (hasMany)**: `categories.parent_id → categories.id`
|
||
|
|
- **products (hasMany)**: `products.category_id → categories.id`
|
||
|
|
- **estimates (hasMany)**: `estimates.model_set_id → categories.id (논리적)`
|
||
|
|
|
||
|
|
### 📋 `products` - 제품 마스터
|
||
|
|
|
||
|
|
- **category (belongsTo)**: `products.category_id → categories.id`
|
||
|
|
- **tenant (belongsTo)**: `products.tenant_id → tenants.id`
|
||
|
|
- **product_components (hasMany)**: `product_components.parent_product_id → products.id (논리적)`
|
||
|
|
- **order_items (hasMany)**: `order_items.product_id → products.id`
|
||
|
|
|
||
|
|
### 📋 `departments` - 부서 관리 (계층구조)
|
||
|
|
|
||
|
|
- **parent (belongsTo)**: `departments.parent_id → departments.id (논리적)`
|
||
|
|
- **children (hasMany)**: `departments.parent_id → departments.id (논리적)`
|
||
|
|
- **tenant (belongsTo)**: `departments.tenant_id → tenants.id`
|
||
|
|
|
||
|
|
### 📋 `estimates` - 견적서 (스냅샷 데이터)
|
||
|
|
|
||
|
|
- **category (belongsTo)**: `estimates.model_set_id → categories.id (논리적)`
|
||
|
|
- **tenant (belongsTo)**: `estimates.tenant_id → tenants.id`
|
||
|
|
- **estimate_items (hasMany)**: `estimate_items.estimate_id → estimates.id (논리적)`
|
||
|
|
|
||
|
|
### 📋 `estimate_items` - 견적 아이템
|
||
|
|
|
||
|
|
- **estimate (belongsTo)**: `estimate_items.estimate_id → estimates.id (논리적)`
|
||
|
|
- **tenant (belongsTo)**: `estimate_items.tenant_id → tenants.id`
|
||
|
|
|
||
|
|
### 📋 `product_components` - BOM 구성요소 (통합 참조구조)
|
||
|
|
|
||
|
|
- **parent_product (belongsTo)**: `product_components.parent_product_id → products.id (논리적)`
|
||
|
|
- **material_or_product (polymorphic)**: `product_components.ref_id → materials.id OR products.id (ref_type 기반)`
|
||
|
|
- **tenant (belongsTo)**: `product_components.tenant_id → tenants.id`
|
||
|
|
|
||
|
|
### 📋 `classifications` - 분류 코드
|
||
|
|
|
||
|
|
- **tenant (belongsTo)**: `classifications.tenant_id → tenants.id (논리적)`
|
||
|
|
|
||
|
|
## 🚨 중요 사항
|
||
|
|
|
||
|
|
### 논리적 관계 (FK 제거됨)
|
||
|
|
- `classifications.tenant_id → tenants.id`
|
||
|
|
- `departments.parent_id → departments.id`
|
||
|
|
- `estimates.model_set_id → categories.id`
|
||
|
|
- `estimate_items.estimate_id → estimates.id`
|
||
|
|
- `product_components` 모든 관계 (통합 구조)
|
||
|
|
|
||
|
|
### 물리적 FK 유지됨
|
||
|
|
- 모든 `tenant_id` 관계 (멀티테넌트 보안)
|
||
|
|
- 권한 관리 시스템 FK
|
||
|
|
- 기타 중요 비즈니스 FK
|
||
|
|
|
||
|
|
## 📝 개발 가이드
|
||
|
|
|
||
|
|
1. **Service 레이어**에서 논리적 무결성 검증 필수
|
||
|
|
2. **Eloquent 관계 메서드** 적극 활용
|
||
|
|
3. **Soft Delete**로 데이터 보호
|
||
|
|
4. **BelongsToTenant** 트레잇으로 테넌트 격리
|
||
|
|
|
||
|
|
---
|
||
|
|
*이 문서는 개발 참조용입니다. 모델 변경 시 업데이트 해주세요.*
|