<?php

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

class CreateEntryPartnerTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('entry_partner', function (Blueprint $table) {
            $table->unsignedBigInteger('entry_id');
            $table->unsignedBigInteger('partner_id');
            $table->unsignedInteger('position')->nullable();
            
            $table->primary(['entry_id', 'partner_id'], 'entry_partner_pk');
            
            $table->foreign('entry_id')->references('id')
                ->on('entries')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->foreign('partner_id')->references('id')
                ->on('partners')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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