<?php

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

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

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

        });
    }

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