feat: [수주관리] order_nodes 테이블 및 모델 생성 (N-depth 트리 구조)

- order_nodes 마이그레이션: 자기참조 parent_id, 고정코어(통계용) + options JSON(하이브리드)
- order_items에 order_node_id nullable FK 추가
- OrderNode 모델: BelongsToTenant, Auditable, SoftDeletes, 트리 관계(parent/children)
- Order 모델: nodes(), rootNodes() HasMany 관계 추가
- OrderItem 모델: order_node_id fillable + node() BelongsTo 관계 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 20:06:14 +09:00
parent 4ae7b438f1
commit 874bf97b8f
5 changed files with 235 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?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::create('order_nodes', function (Blueprint $table) {
$table->id()->comment('ID');
$table->foreignId('tenant_id')->comment('테넌트 ID');
$table->foreignId('order_id')->comment('수주 ID');
// ---- 트리 구조 ----
$table->foreignId('parent_id')->nullable()->comment('상위 노드 ID (NULL=루트)');
// ---- 고정 코어 (통계/집계용) ----
$table->string('node_type', 50)->comment('노드 유형 (location, zone, floor, room, process...)');
$table->string('code', 100)->comment('식별 코드');
$table->string('name', 200)->comment('표시명');
$table->string('status_code', 30)->default('PENDING')
->comment('상태 (PENDING/CONFIRMED/IN_PRODUCTION/PRODUCED/SHIPPED/COMPLETED/CANCELLED)');
$table->integer('quantity')->default(1)->comment('수량');
$table->decimal('unit_price', 15, 2)->default(0)->comment('단가');
$table->decimal('total_price', 15, 2)->default(0)->comment('합계');
// ---- 유연 확장 (유형별 상세) ----
$table->json('options')->nullable()->comment('유형별 동적 속성 JSON');
// ---- 정렬 ----
$table->integer('depth')->default(0)->comment('트리 깊이 (0=루트)');
$table->integer('sort_order')->default(0)->comment('정렬 순서');
// ---- 감사 ----
$table->foreignId('created_by')->nullable()->comment('생성자 ID');
$table->foreignId('updated_by')->nullable()->comment('수정자 ID');
$table->foreignId('deleted_by')->nullable()->comment('삭제자 ID');
$table->timestamps();
$table->softDeletes();
// ---- 인덱스 ----
$table->index('tenant_id');
$table->index('parent_id');
$table->index(['order_id', 'depth', 'sort_order']);
$table->index(['order_id', 'node_type']);
$table->index(['tenant_id', 'node_type', 'status_code']); // 통계용
});
}
public function down(): void
{
Schema::dropIfExists('order_nodes');
}
};

View File

@@ -0,0 +1,27 @@
<?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('order_items', function (Blueprint $table) {
$table->foreignId('order_node_id')
->nullable()
->after('order_id')
->comment('수주 노드 ID (order_nodes)');
$table->index('order_node_id');
});
}
public function down(): void
{
Schema::table('order_items', function (Blueprint $table) {
$table->dropIndex(['order_node_id']);
$table->dropColumn('order_node_id');
});
}
};