<?php

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

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

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