<?php

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

class CapsuleCommentReportTable extends Migration
{
	const TABLE = 'table_capsule_comment_report';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create(static::TABLE, function (Blueprint $table) {
            $table->increments('id');
			$table->unsignedInteger('comment_id');
			$table->unsignedInteger('by_user_id');

			$table->timestamp('created_at');

			$table->unique(['comment_id', 'by_user_id']);

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

            $table->index('created_at');
		});

        \DB::table('table_manager_permission')->insert([
            'role_id' => 1, 'value' => 'reported_comments'
        ]);
	}

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