<?php

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

class NotificationTable extends Migration
{
	const table_user_notification = 'table_user_notification';

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

		    $table->uuid('uuid');
			$table->increments('id');

			$table->unsignedInteger('user_id')->nullable();
			$table->unsignedInteger('owner_id')->nullable();
			$table->unsignedInteger('comment_id')->nullable();
			$table->unsignedInteger('capsule_id')->nullable();

			$table->boolean('is_seen')->nullable();
			$table->tinyInteger('type')->nullable();
			$table->string('content')->nullable();
			$table->integer('created_at_micro')->nullable();

			$table->string('hash');

			$table->timestamps();

            // Relations
            $table->foreign('user_id')->references('id')->on('table_user')->onDelete('cascade');
            $table->foreign('owner_id')->references('id')->on('table_user')->onDelete('cascade');
            $table->foreign('comment_id')->references('id')->on('table_capsule_comment')->onDelete('cascade');
            $table->foreign('capsule_id')->references('id')->on('table_capsule')->onDelete('cascade');

            $table->index('is_seen');
            $table->index('type');
            $table->index('created_at_micro');
            $table->index('created_at');
            $table->index('updated_at');
		});

	}

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