<?php

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

class AddBlocksCardsPivotTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('block_cards', function (Blueprint $table) {
            $table->unsignedInteger('block_id');
            $table->unsignedInteger('generic_block_id');
            $table->unsignedInteger('position')->default(1);
            $table->primary(['block_id', 'generic_block_id'], 'PK_block_cards');

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

        });
    }

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