<?php

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

class CreateEventItemBlocksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('event_item_blocks', function (Blueprint $table) {
            $table->unsignedInteger('event_item_id');
            $table->unsignedInteger('block_id');
            $table->unsignedInteger('position');
            $table->primary(['event_item_id', 'block_id'], 'PK_block_event_item');

            $table->foreign('event_item_id')
                ->references('id')->on('event_items')
                ->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('block_id')
                ->references('id')->on('blocks')
                ->onDelete('CASCADE')->onUpdate('CASCADE');

        });
    }

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