<?php

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

class CreatePropertyAdditionalInfoKeyTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('property_additional_info_key', function (Blueprint $table) {
            $table->increments('id');
            $table->string('additional_info_key',100);
            $table->tinyInteger('status')->default(1);
            $table->unsignedInteger('created_by');
            $table->unsignedInteger('updated_by');
            $table->integer('created_at');
            $table->integer('updated_at');
        });

        Schema::create('property_additional_info_key_locale', function (Blueprint $table) {

            $table->increments('id');
            $table->unsignedInteger('additional_info_key_id');
            $table->string('additional_info_key',200);
            $table->string('locale',2);
            $table->tinyInteger('status')->default(1);
            $table->unsignedInteger('created_by');
            $table->unsignedInteger('updated_by');
            $table->integer('created_at');
            $table->integer('updated_at');
        });

        Schema::table('property_additional_info_key', function (Blueprint $table) {
            $table->foreign('created_by')->references('id')->on('user');
            $table->foreign('updated_by')->references('id')->on('user');
            $table->unique(['additional_info_key'],'padilk_unique');
        });

        Schema::table('property_additional_info_key_locale', function (Blueprint $table) {
            $table->foreign('additional_info_key_id','paikl_additional_info_key_id_fk')->references('id')->on('property_additional_info_key');
            $table->foreign('created_by')->references('id')->on('user');
            $table->foreign('updated_by')->references('id')->on('user');
            $table->unique(['additional_info_key_id','locale'],'padilkl_unique');
        });
    }

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