<?php

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

class CreateWebsiteObjectsSearchTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('website_objects_search', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('website_object_id');
            $table->string('language_id', 10);
            $table->longText('primary_search');
            $table->longText('secondary_search');
            $table->unsignedInteger('image_id')->nullable();
            $table->string('title', 255);
            $table->text('content')->nullable();
            $table->string('content_type', 100);
            $table->string('group_label', 100);
            $table->string('uri', 255);


            $table->unique(['website_object_id', 'language_id']);
            $table->index('language_id');
        });

        DB::statement('ALTER TABLE website_objects_search ADD FULLTEXT idx_website_objects_search_ft(primary_search, secondary_search)');
        DB::statement('ALTER TABLE website_objects_search ADD FULLTEXT idx_website_objects_primary_search_ft(primary_search)');
        DB::statement('ALTER TABLE website_objects_search ADD FULLTEXT idx_website_objects_secondary_search_ft(secondary_search)');
    }

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