Files
sam-api/database/migrations/2025_12_17_100002_create_purchases_table.php

48 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('purchases', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
$table->string('purchase_number', 30)->comment('매입번호');
$table->date('purchase_date')->comment('매입일자');
$table->unsignedBigInteger('client_id')->comment('거래처 ID');
$table->decimal('supply_amount', 15, 2)->comment('공급가액');
$table->decimal('tax_amount', 15, 2)->comment('세액');
$table->decimal('total_amount', 15, 2)->comment('합계');
$table->text('description')->nullable()->comment('적요');
$table->string('status', 20)->default('draft')->comment('상태: draft/confirmed');
$table->unsignedBigInteger('withdrawal_id')->nullable()->comment('출금 연결 ID');
$table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
$table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
$table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자');
$table->softDeletes();
$table->timestamps();
// 인덱스
$table->unique(['tenant_id', 'purchase_number'], 'uk_tenant_purchase_number');
$table->index(['tenant_id', 'purchase_date'], 'idx_tenant_purchase_date');
$table->index('client_id', 'idx_client');
$table->index('status', 'idx_status');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('purchases');
}
};