- Pint 스타일 이슈 25개 수정 (783 파일 통과) - 마이그레이션 4개 실행 (payrolls, payroll_settings, push 테이블) - routes/api.php import 정렬
104 lines
5.4 KiB
PHP
104 lines
5.4 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
/**
|
|
* Items 통합 테이블 생성
|
|
*
|
|
* Products + Materials 테이블을 단일 items 테이블로 통합
|
|
* - FG, PT (Products) + SM, RM, CS (Materials) → item_type으로 구분
|
|
* - BOM에서 child_item_type 불필요 (ID만으로 유일 식별)
|
|
* - 단일 쿼리로 모든 품목 조회 가능
|
|
*/
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
Schema::create('items', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
|
|
|
|
// 기본 정보
|
|
$table->string('item_type', 10)->comment('품목 유형: FG, PT, SM, RM, CS');
|
|
$table->string('code', 100)->comment('품목 코드');
|
|
$table->string('name', 255)->comment('품목명');
|
|
$table->string('unit', 20)->nullable()->comment('단위');
|
|
$table->unsignedBigInteger('category_id')->nullable()->comment('카테고리 ID');
|
|
|
|
// 상세 정보
|
|
$table->text('specification')->nullable()->comment('규격 (Materials용)');
|
|
$table->text('description')->nullable()->comment('설명');
|
|
|
|
// JSON 필드
|
|
$table->json('attributes')->nullable()->comment('동적 속성');
|
|
$table->json('attributes_archive')->nullable()->comment('속성 아카이브');
|
|
$table->json('options')->nullable()->comment('옵션 [{label, value, unit}]');
|
|
$table->json('bom')->nullable()->comment('BOM [{child_item_id, quantity}]');
|
|
|
|
// Products 전용 필드
|
|
$table->boolean('is_sellable')->default(true)->comment('판매 가능');
|
|
$table->boolean('is_purchasable')->default(false)->comment('구매 가능');
|
|
$table->boolean('is_producible')->default(false)->comment('생산 가능');
|
|
$table->integer('safety_stock')->nullable()->comment('안전 재고');
|
|
$table->integer('lead_time')->nullable()->comment('리드타임 (일)');
|
|
$table->boolean('is_variable_size')->default(false)->comment('가변 사이즈 여부');
|
|
$table->string('product_category', 50)->nullable()->comment('제품 카테고리');
|
|
$table->string('part_type', 50)->nullable()->comment('부품 유형');
|
|
|
|
// 파일 필드 (Products)
|
|
$table->string('bending_diagram', 255)->nullable()->comment('절곡 도면 파일');
|
|
$table->json('bending_details')->nullable()->comment('절곡 상세 정보');
|
|
$table->string('specification_file', 255)->nullable()->comment('시방서 파일');
|
|
$table->string('specification_file_name', 255)->nullable()->comment('시방서 파일명');
|
|
$table->string('certification_file', 255)->nullable()->comment('인증서 파일');
|
|
$table->string('certification_file_name', 255)->nullable()->comment('인증서 파일명');
|
|
$table->string('certification_number', 100)->nullable()->comment('인증 번호');
|
|
$table->date('certification_start_date')->nullable()->comment('인증 시작일');
|
|
$table->date('certification_end_date')->nullable()->comment('인증 종료일');
|
|
|
|
// Materials 전용 필드
|
|
$table->string('item_name', 255)->nullable()->comment('품명 (Materials)');
|
|
$table->string('is_inspection', 1)->default('N')->comment('검사 대상 여부');
|
|
$table->string('search_tag', 255)->nullable()->comment('검색 태그');
|
|
$table->text('remarks')->nullable()->comment('비고');
|
|
|
|
// 레거시 참조 (전환기간용)
|
|
$table->string('legacy_table', 20)->nullable()->comment('원본 테이블: products | materials');
|
|
$table->unsignedBigInteger('legacy_id')->nullable()->comment('원본 테이블 ID');
|
|
|
|
// 공통 필드
|
|
$table->boolean('is_active')->default(true)->comment('활성 상태');
|
|
$table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
|
|
$table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
|
|
$table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자');
|
|
$table->timestamps();
|
|
$table->softDeletes();
|
|
|
|
// 인덱스
|
|
$table->index(['tenant_id', 'item_type'], 'idx_items_tenant_type');
|
|
$table->index(['tenant_id', 'code'], 'idx_items_tenant_code');
|
|
$table->index(['tenant_id', 'category_id'], 'idx_items_tenant_category');
|
|
$table->index(['tenant_id', 'is_active'], 'idx_items_tenant_active');
|
|
$table->index(['legacy_table', 'legacy_id'], 'idx_items_legacy');
|
|
|
|
// 유니크 제약 (tenant_id + code + deleted_at)
|
|
// MySQL에서는 deleted_at이 NULL인 경우를 위해 함수 인덱스 대신 별도 처리
|
|
$table->unique(['tenant_id', 'code', 'deleted_at'], 'uq_items_tenant_code');
|
|
|
|
// 외래키
|
|
$table->foreign('tenant_id')->references('id')->on('tenants');
|
|
$table->foreign('category_id')->references('id')->on('categories')->onDelete('set null');
|
|
});
|
|
|
|
// 테이블 코멘트
|
|
\DB::statement("ALTER TABLE items COMMENT = 'Products + Materials 통합 품목 테이블'");
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('items');
|
|
}
|
|
};
|