<?php

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

class CreateChronologyEpigraphTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('chronology_epigraph', function (Blueprint $table) {
            $table->unsignedBigInteger('chronology_id');
            $table->unsignedBigInteger('epigraph_id');
            $table->unsignedInteger('position')->nullable();
            
            $table->primary(['chronology_id', 'epigraph_id'], 'chronology_epigraph_pk');
            
            $table->foreign('chronology_id')->references('id')
                ->on('chronologies')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->foreign('epigraph_id')->references('id')
                ->on('epigraphs')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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