<?php

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

class CreateContentModuleInfographicTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('content_module_infographic', function (Blueprint $table) {
            $table->unsignedInteger('content_module_id');
            $table->unsignedInteger('infographic_id');
            $table->unsignedInteger('position')->nullable();

            $table->primary(['content_module_id', 'infographic_id'], 'module_infographic_pk');
            $table->foreign('infographic_id')->references('id')
                ->on('infographics')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('content_module_id')->references('id')
                ->on('content_modules')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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