<?php

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

class CreateInventoryDailyLogsTable extends Migration
{
    protected $authNames=[
        '库存管理-库存体积',
        '库存管理-库存体积-管理监听货主',
    ];

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('inventory_daily_logs', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('owner_id')->index()->comment('外键货主表');
            $table->timestamp('created_at')->index()->comment('记录时间');
            $table->bigInteger('commodity_id')->index()->comment('外键商品表');
            $table->integer('amount')->default(0)->comment('数量');
            $table->decimal('volumn_occupied',11,3)->nullable()->default(null)->comment('占用体积');
        });
        foreach ($this->authNames as $name){
            \App\Authority::query()->create(['name'=>$name,'alias_name'=>$name]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('inventory_daily_logs');
        foreach ($this->authNames as $name){
            \App\Authority::query()->where(['name'=>$name,'alias_name'=>$name])->delete();
        }
    }
}
