<?php

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

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

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