<?php

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

class CreateCharacterPhraseTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('character_phrase', function (Blueprint $table) {
            $table->unsignedBigInteger('character_id');
            $table->unsignedBigInteger('phrase_id');
            $table->unsignedInteger('position')->nullable();
            
            $table->primary(['character_id', 'phrase_id'], 'character_phrase_pk');
            
            $table->foreign('character_id')->references('id')
                ->on('characters')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->foreign('phrase_id')->references('id')
                ->on('phrases')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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