30 lines
1.1 KiB
PHP
30 lines
1.1 KiB
PHP
<?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('stocks', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('sku_code')->index()->comment('商品编码');
|
|
$table->string('sku_name')->comment('商品名称(冗余)');
|
|
$table->foreignId('warehouse_id')->constrained()->onDelete('cascade');
|
|
$table->integer('quantity')->default(0)->comment('实际库存');
|
|
$table->integer('locked_quantity')->default(0)->comment('锁定库存');
|
|
$table->integer('available_quantity')->storedAs('quantity - locked_quantity')->comment('可用库存(计算字段)');
|
|
$table->integer('warning_threshold')->default(0)->comment('预警阈值');
|
|
$table->timestamps();
|
|
|
|
$table->unique(['sku_code', 'warehouse_id']);
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('stocks');
|
|
}
|
|
}; |