<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('shop_product_stocks', function (Blueprint $table) {
            // Drop the old unique index
            $table->dropUnique('shop_product_stocks_shop_product_id_shop_id_unique');

            // Add new nullable column
            // $table->integer('length')->nullable()->after('stock');

            // Add new unique index including length
            // $table->unique(['shop_product_id', 'shop_id', 'length'], 'shop_product_stocks_unique_new');
        });
    }

    public function down(): void
    {
        Schema::table('shop_product_stocks', function (Blueprint $table) {
            // Drop the new unique index
            $table->dropUnique('shop_product_stocks_unique_new');

            // Drop length column
            // $table->dropColumn('length');

            // Recreate the old unique index
            $table->unique(['shop_product_id', 'shop_id'], 'shop_product_stocks_shop_product_id_shop_id_unique');
        });
    }
};
