<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDailyStockRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('daily_stock_records', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('sku_id')->nullable(false);
            $table->date('day')->nullable(false);
            $table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货');
            $table->unsignedInteger('loss_num')->default(0)->comment('损耗');
            $table->unsignedInteger('inventory')->default(0)->comment('库存盘点');
            $table->timestamps();
            // 索引
            $table->unique(['sku_id', 'day']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('daily_stock_records');
    }
}
