<?php

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

class CreateArtistExhibition extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::create('artist_exhibition', function (Blueprint $table) {
            $table->unsignedBigInteger('exhibition_id');
            $table->unsignedBigInteger('artist_id');
            $table->integer('position')->nullable();
            $table->primary(['exhibition_id', 'artist_id']);

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

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