<?php

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

class CreateGoodsSkusTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::defaultStringLength(191);
        Schema::create('goods_skus', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('goods_id')->nullable(false)->comment('商品id');
            $table->string('title')->nullable(false)->comment('商品规格');
            $table->string('sku_code', 32)->nullable(false)->comment('规格编码');
            $table->unsignedTinyInteger('status')->default(0)->comment('规格状态(0-下架,1在售,2预警)');
            $table->unsignedInteger('num')->default(0)->comment('总量');
            $table->unsignedInteger('stock')->default(0)->comment('库存');
            $table->unsignedDecimal('cost')->default(0)->comment('成本');
            $table->unsignedInteger('two_days_ago_num')->default(0)->comment('2天前库存');
            $table->unsignedInteger('yesterday_num')->default(0)->comment('1天前库存');
            $table->unsignedDecimal('reference_price')->default(0)->comment('参考售价');
            $table->unsignedInteger('reserve')->default(0)->comment('预留量');
            $table->timestamps();
            // 索引
            $table->unique(['goods_id', 'sku_code']);
        });
    }

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