<?php

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

class CreateUserHistoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_histories', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id');

            $table->unsignedInteger('shopping_order_id')->nullable();
            $table->unsignedInteger('product_id')->nullable();

            $table->string('action')->index()->nullable();
            $table->unsignedInteger('referenz')->default(0);
            $table->string('identifier')->index()->nullable();

            $table->boolean('abo_options')->default(false);

            $table->unsignedTinyInteger('status')->index()->default(0);

            $table->timestamps();


            $table->foreign('shopping_order_id')
                ->references('id')
                ->on('shopping_orders');


            $table->foreign('product_id')
                ->references('id')
                ->on('products');

            $table->foreign('user_id')
                ->references('id')
                ->on('users')
                ->onDelete('cascade');
        });
    }

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