<?php

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

class UsersCapsulesSearchUpdate extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('table_user', function (Blueprint $table) {
            $table->removeColumn('is_influence');
            $table->removeColumn('influence_position');
        });

        Schema::table('table_capsule', function (Blueprint $table) {
            /** Show for new users or for all */
            $table->unsignedInteger('search_setting')->default(0)->nullable();
            $table->unsignedBigInteger('search_position')->default(0)->nullable();
            $table->unsignedBigInteger('suggested_position')->default(0)->nullable();

            $table->index('search_setting');
            $table->index('search_position');
            $table->index('suggested_position');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('table_user', function (Blueprint $table) {
            $table->boolean('is_influence')->default(false);
            $table->integer('influence_position')->default(0);

            $table->index('is_influence');
            $table->index('influence_position');
        });

        Schema::table('table_capsule', function (Blueprint $table) {
            $table->dropColumn('search_setting');
            $table->dropColumn('search_position');
            $table->dropColumn('suggested_position');
        });
    }
}
