<?php

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

class AddExternalSkuIdToGoodsSkusTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasColumn('goods_skus', 'external_sku_id')) {
            return;
        }
        Schema::defaultStringLength(191);
        Schema::table('goods_skus', function (Blueprint $table) {
            $table->string('external_sku_id')->default('')->nullable();
            $table->tinyInteger('is_combination')->default(0);
            $table->index('external_sku_id');
            $table->index('is_combination');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('goods_skus', function (Blueprint $table) {
            $table->dropColumn('external_sku_id');
            $table->dropIndex('external_sku_id');
        });
    }
}
