<?php

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

class CreateWithdrawHistoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('withdraw_histories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('withdraw_id');
            $table->unsignedBigInteger('withdraw_status_id');
            $table->unsignedBigInteger('user_id')->index();
            $table->decimal('amount',8,2)->index()->default(0);
            $table->string('remark')->index()->nullable();
            $table->boolean('status')->index()->default(true);
            $table->timestamps();
            $table->softDeletes();
            $table->foreign('withdraw_id')->references('id')->on('withdraws')->onDelete('cascade');
            $table->foreign('withdraw_status_id')->references('id')->on('withdraw_statuses')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

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