<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::table('shop_customers', function (Blueprint $table) {
            if (! Schema::hasColumn('shop_customers', 'default_sale_channel_id')) {
                $table->unsignedInteger('default_sale_channel_id')->nullable()->after('settings');
                $table->index('default_sale_channel_id', 'shop_customers_default_sale_channel_id_index');
            }
        });
    }

    public function down()
    {
        Schema::table('shop_customers', function (Blueprint $table) {
            if (Schema::hasColumn('shop_customers', 'default_sale_channel_id')) {
                $table->dropIndex('shop_customers_default_sale_channel_id_index');
                $table->dropColumn('default_sale_channel_id');
            }
        });
    }
};
