<?php

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

class CreateCollectionExhibitionTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('collection_exhibition', function (Blueprint $table) {
            $table->unsignedBigInteger('collection_id');
            $table->unsignedBigInteger('exhibition_id');
            $table->integer('position')->nullable();

            $table->primary(['collection_id', 'exhibition_id']);

            $table->foreign('collection_id')->references('id')
                ->on('collections')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('exhibition_id')->references('id')
                ->on('exhibitions')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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