<?php

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

class CreateFilterItemsAssociationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('filter_items_associations', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('filter_item_id');
            $table->integer('filter_items_associations_id');
            $table->string('filter_items_associations_type');
            $table->unique([
                'filter_item_id',
                'filter_items_associations_id',
                'filter_items_associations_type'
            ], 'filter_item_id_model_id_type_unique');
            $table->timestamps();
        });

        Schema::table('filter_items_associations', function (Blueprint $table) {
            $table->foreign('filter_item_id')->references('id')->on('filter_items');
        });
    }

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

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