<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEntryPageSectionTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('entry_page_section', function (Blueprint $table) {
            $table->unsignedInteger('entry_id');
            $table->unsignedInteger('page_section_id');
            $table->unsignedInteger('position')->nullable();

            $table->primary(['entry_id', 'page_section_id']);
            $table->foreign('entry_id')->references('id')
                ->on('entries')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('page_section_id')->references('id')
                ->on('page_sections')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('entry_page_section');
    }
}
