<?php

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

class CapsuleCommentTable extends Migration
{
	const TABLE = 'table_capsule_comment';

	protected function commentTable()
	{
		Schema::create(static::TABLE, function (Blueprint $table) {
			$table->increments('id');
			$table->uuid('uuid')->unique();

			$table->unsignedInteger('user_id')->nullable();
			$table->unsignedInteger('capsule_id')->nullable();
			$table->text('content')->nullable();

			$table->softDeletes();
			$table->timestamps();

            $table->foreign('user_id')->references('id')->on(UserTable::TABLE)->onDelete('cascade');
            $table->foreign('capsule_id')->references('id')->on(AllCapsuleTable::TABLE)->onDelete('cascade');

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

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		$this->commentTable();
	}

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