<?php

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

class CreateBlockVideoTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('block_video', function (Blueprint $table) {
            $table->unsignedBigInteger('block_id');
            $table->unsignedBigInteger('video_id');
            $table->unsignedInteger('position')->nullable();
            
            $table->primary(['block_id', 'video_id'], 'block_video_pk');
            
            $table->foreign('block_id')->references('id')
                ->on('blocks')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->foreign('video_id')->references('id')
                ->on('videos')->onDelete('CASCADE')->onUpdate('CASCADE');
            
            $table->timestamps();
        });
    }

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