<?php

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

class CreateLearningProductSynonym extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('learning_product_synonym', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('synonym_id');
            $table->unsignedInteger('learning_product_id');
            $table->unique([
                'synonym_id',
                'learning_product_id',
            ], 'synonym_id_learning_product_id_unique');
        });

        Schema::table('learning_product_synonym', function (Blueprint $table) {
            $table->foreign('synonym_id')->references('id')->on('synonyms')->onDelete('cascade');
            $table->foreign('learning_product_id')->references('id')->on('learning_products')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('learning_product_synonym', function (Blueprint $table) {
            $table->dropForeign('learning_product_synonym_synonym_id_foreign');
            $table->dropForeign('learning_product_synonym_learning_product_id_foreign');
        });

        Schema::dropIfExists('learning_product_synonym');
    }
}
