<?php

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

class CreateUserMentionedTable extends Migration
{
    const TABLE = 'table_user_mention';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create(static::TABLE, function (Blueprint $table) {

            $table->increments('id');
            $table->uuid('user_uuid');
            $table->unsignedInteger('capsule_id')->nullable();
            $table->unsignedInteger('comment_id')->nullable();
            $table->timestamps();

            $table->foreign('capsule_id')->references('id')->on('table_capsule')->onDelete('cascade');
            $table->foreign('comment_id')->references('id')->on('table_capsule_comment')->onDelete('cascade');

            $table->index('user_uuid');
            $table->index('capsule_id');
            $table->index('comment_id');
        });
    }

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