<?php

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

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

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