<?php

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

class CreatePropertyFactMappingTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('property_fact_mapping', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('property_id')->unsigned();
            $table->integer('fact_id')->unsigned();
            $table->integer('attribute_id')->unsigned()->nullable();
            $table->integer('unit_id')->unsigned()->nullable();
            $table->string('value',100)->nullable()->default(null);
            $table->unsignedInteger('created_by');
            $table->unsignedInteger('updated_by');
            $table->integer('created_at');
            $table->integer('updated_at');
        });

        Schema::table('property_fact_mapping',function (Blueprint $table) {
            $table->foreign('property_id')->references('id')->on('property');
            $table->foreign('fact_id')->references('id')->on('property_fact');
            $table->foreign('attribute_id')->references('id')->on('property_fact_attribute');
            $table->foreign('unit_id')->references('id')->on('property_unit');
            $table->unique(['property_id', 'fact_id','attribute_id'],'pfam_unique');
        });
    }

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